472,145 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

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
2 2418
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 | last post: by
2 posts views Thread by Sektor | last post: by
reply views Thread by leo001 | last post: by

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.