Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 tSQL = Operator Trims operands before comparison

Author  Topic 

jfuex
Starting Member

29 Posts

Posted - 2009-09-09 : 10:59:38
Noticed some odd behavior today in tSQL (200,2005,and 2008).

It appears that the equivalence operator(=) removes trailing spaces from both operands before comparing them.

To demonstrate, try the following code and note the surprising results (each line prints 'equal')

if '' = ' ' print 'equal' else print 'not equal'
if ' ' = ' ' print 'equal' else print 'not equal'
if ' ' = ' ' print 'equal' else print 'not equal'
if 'abc' = 'abc ' print 'equal' else print 'not equal'

I can't find any reference to this behavior in BOL or other MSDN documentation and am curious about whether this is by design and if so, why?

Seems like this could introduce some major logic bugs

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-09-09 : 11:06:15
http://support.microsoft.com/kb/316626
Go to Top of Page
   

- Advertisement -