467,083 Members | 1,259 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,083 developers. It's quick & easy.

Why select ... where 'Anna ' = 'Anna' returns TRUE?

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.

How to change it to return FALSE what is my expected value?
Jul 20 '05 #1
  • viewed: 2268
Share:
2 Replies
ae***@op.pl (Robert Zientara) wrote in message news:<de**************************@posting.google. com>...
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.

How to change it to return FALSE what is my expected value?


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...;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')

Simon
Jul 20 '05 #2
"Robert Zientara" <ae***@op.pl> wrote in message
news:de**************************@posting.google.c om...
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. How to change it to return FALSE what is my expected value?


Check .... SET ANSI_PADDING

Also RTRIM

Pete Brown
Falls Creek
Oz
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Reestit Mutton | last post: by
4 posts views Thread by Anna Smith | last post: by
1 post views Thread by Christopher DeMarco | last post: by
2 posts views Thread by areef.islam@gmail.com | last post: by
2 posts views Thread by Sektor | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.