473,739 Members | 7,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unexpected LIKE behavior

SQL Server 2000 SP4.

Running the script below prints 'Unexpected':

-----------------------------
DECLARE @String AS varchar(1)

SELECT @String = 'z'

IF @String LIKE '[' + CHAR(32) + '-' + CHAR(255) + ']'
PRINT 'Expected'
ELSE
PRINT 'Unexpected'
-----------------------------

If the @String variable is set to 'y' (or in fact any ANSI character other
than 'z'), the result is 'Expected'. The comparison also evaluates as
expected if CHAR(255) is replaced with CHAR(254). The server collation, if
that matters, is SQL_Latin1_Gene ral_CP1_CI_AS.

It would be helpful to find the explanatin of this behavior. Thanks.

--
(remove a 9 to reply by email)
Apr 22 '07 #1
2 2069
Dimitri Furman wrote:
SQL Server 2000 SP4.

Running the script below prints 'Unexpected':

-----------------------------
DECLARE @String AS varchar(1)

SELECT @String = 'z'

IF @String LIKE '[' + CHAR(32) + '-' + CHAR(255) + ']'
PRINT 'Expected'
ELSE
PRINT 'Unexpected'
-----------------------------

If the @String variable is set to 'y' (or in fact any ANSI character other
than 'z'), the result is 'Expected'. The comparison also evaluates as
expected if CHAR(255) is replaced with CHAR(254). The server collation, if
that matters, is SQL_Latin1_Gene ral_CP1_CI_AS.

It would be helpful to find the explanatin of this behavior. Thanks.
CHAR(255) = 'y' with an umlaut
http://englishplus.com/xascii.htm
Apr 22 '07 #2
Dimitri Furman (df*****@cloud9 9.net) writes:
SQL Server 2000 SP4.

Running the script below prints 'Unexpected':

-----------------------------
DECLARE @String AS varchar(1)

SELECT @String = 'z'

IF @String LIKE '[' + CHAR(32) + '-' + CHAR(255) + ']'
PRINT 'Expected'
ELSE
PRINT 'Unexpected'
-----------------------------

If the @String variable is set to 'y' (or in fact any ANSI character other
than 'z'), the result is 'Expected'. The comparison also evaluates as
expected if CHAR(255) is replaced with CHAR(254). The server collation, if
that matters, is SQL_Latin1_Gene ral_CP1_CI_AS.

It would be helpful to find the explanatin of this behavior. Thanks.
I suspect that this is a case of wrong expectations. When you have a
range in a pattern, it is not defined from ASCII codes, but from the
collation. Only if the collation is a binary collation, character codes
apply. As Ed said char(255) is ÿ, so z is definitely outside the range.

This prints "Expected":

DECLARE @String AS varchar(1)

SELECT @String = 'z'

IF @String COLLATE Latin1_General_ BIN
LIKE '[' + CHAR(32) + '-' + CHAR(255) + ']'
PRINT 'Expected'
ELSE
PRINT 'Unexpected'
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
2440
by: He Shiming | last post by:
Hi, I'm having a little bit of trouble regarding pointer casting in my program. I don't understand why the following two cases produce different results. Case 1: IInterface *pInterface = new CImplementation(); pInterface->Method(); Case 2:
7
1693
by: Dave Hansen | last post by:
OK, first, I don't often have the time to read this group, so apologies if this is a FAQ, though I couldn't find anything at python.org. Second, this isn't my code. I wouldn't do this. But a colleague did, got an unexpected result, and asked me why. I think I can infer what is occurring, and I was able to find a simple work-around. But I thought I'd ask about it anyway. I've been pushing Python at work for use as a scripting...
4
1779
by: Generic Usenet Account | last post by:
I am seeing some unexpected behavior while using the STL "includes" algorithm. I am not sure if this is a bug with the template header files in our STL distribution, or if this is how it should work. For your benefit, let me first quote from the STL Standard Reference (Stepanov & Lee): template <class InputIterator1, class InputIterator2> bool includes(InputIterator1 first1, InputIterator1 last1,InputIterator2 first2, InputIterator2...
6
3182
by: Cro | last post by:
Dear Access Developers, The 'Allow Additions' property of my form is causing unexpected results. I am developing a form that has its 'Default View' property set to 'Continuous Forms' and am displaying records that match an SQL statement entered in the 'Record Source' property of the form. The form behaves correctly and displays the records as expected. The
9
2180
by: Jeff Louie | last post by:
In C# (and C++/cli) the destructor will be called even if an exception is thrown in the constructor. IMHO, this is unexpected behavior that can lead to an invalid system state. So beware! http://www.geocities.com/jeff_louie/oop30.htm Regards, Jeff *** Sent via Developersdex http://www.developersdex.com ***
62
3780
by: ashu | last post by:
hi look at this code include <stdio.h> int main(void) { int i,j=2; i=j++ * ++j * j++; printf("%d %d",i,j); return 0;
4
1626
by: duffdevice | last post by:
Hi, I came across this unexpected behavior while working on something else. I am attempting to return a custom type by value from a global function. I have a trace in the custom class's copy constructor, and I expected this code to tell me that the custom copy constructor had been called twice. Instead, it's only called once and the program executes correctly. Is this an optimization related to my compiler (g++ v4.0.1) or is this...
2
1704
by: mbeachy | last post by:
Some rather unexpected behavior in the set_default/set_defaults methods for OptionParser that I noticed recently: <Option at 0x-483b3414: -r/--restart> {'restart': None} {'retart': False, 'restart': None} Why does set_default not raise an exception when passed a key that it doesn't recognize?
1
3661
by: Kevin Walzer | last post by:
I'm trying to toggle the visibility of a Tkinter widget using pack_forget(), and I'm running into unexpected behavior. The widget "hides" correctly, but does not become visible again. My sample code is below: ---- from Tkinter import * root = Tk()
0
8792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9266
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.