all groups > sql server programming > december 2006 >
You're in the

sql server programming

group:

Character range comparison, a bug in SQL Server ? Is anyone else getting the same result ?



Re: Character range comparison, a bug in SQL Server ? Is anyone else getting the same result ? Tom Cooper
12/6/2006 12:08:08 PM
sql server programming: In SQL, character ranges must be done with -, not .. [A..Z] is the same
kind of thing as [ABC], just a list of allowed choices. So only 'A', 'Z',
and '.' match [A..Z].

Try

Select
Case When 'A' Like '[A..Z]' Then 'A Yes' Else 'A No' End,
Case When 'B' Like '[A..Z]' Then 'B Yes' Else 'B No' End,
Case When '.' Like '[A..Z]' Then '. Yes' Else '. No' End

to demonstrate this.
Tom

[quoted text, click to view]

Character range comparison, a bug in SQL Server ? Is anyone else getting the same result ? GMG
12/6/2006 11:33:39 PM
Basically, I have found that .. and - give different results in a character
range comparison.

[A-Z] will behave differently to [A..Z]

See article below:

http://www.mssql.com.au/kb/html/gmgxsl.dll/htmlkb?usexsl=y&sp=psearch_articl
e_text&@sa_id=66




Re: Character range comparison, a bug in SQL Server ? Is anyone else getting the same result ? GMG
12/12/2006 12:00:00 AM
I agree with all of you. My testing was flawed (in my defence it was
uproaching midnight).
I was having trouble forcing character comparisons to a case sensitive
collation (the database has a case insensitive collation).
I ended up using a varbinary cast:

if (cast(@Password as varbinary(50)) = cast(lower(@Password) as
varbinary(50)))
print 'Password must contain at least 1 uppercase character (A..Z)'


[quoted text, click to view]

AddThis Social Bookmark Button