Groups | Blog | Home
all groups > sql server (alternate) > january 2004 >

sql server (alternate) : Why select ... where 'Anna ' = 'Anna' returns TRUE?


aeror NO[at]SPAM op.pl
1/29/2004 2:55:53 AM
Sorry for asking stupid questions...

I can't remember which settings in MS SQL define the behaviour of this comparison:

select * from table where 'Anna ' = 'Anna'

to be TRUE. Both strings are different because the first contains trailing blanks.

sql NO[at]SPAM hayes.ch
1/29/2004 7:16:22 AM
[quoted text, click to view]

You may be thinking of SET ANSI_PADDING, but that applies to how
strings are stored in tables, not how they are compared. SQL Server
ignores trailing blanks for non-Unicode data:

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q316626

It would be useful to know the data types of the columns/variables
you're working with, but one possible query to get only exact matches
(on the basis of the length of the string) might be this:

select *
from table
where column = 'Anna' and
datalength(column) = datalength('Anna')

mountain man
1/29/2004 4:09:18 PM
[quoted text, click to view]

Check .... SET ANSI_PADDING

Also RTRIM





Pete Brown
Falls Creek
Oz

AddThis Social Bookmark Button