August 9, 2016 at 4:25 pm
Can someone please tell me why the following code returns 1 instead of 0?
[font="Courier New"]select case when 'a' = 'a ' then 1 else 0 end as Result[/font]
August 9, 2016 at 4:29 pm
You really don't need to use such a large font...
SQL ignores trailing spaces when comparing strings. If it didn't, you'd never be able to compare a char(10) to any other length char or any length varchar.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 9, 2016 at 4:36 pm
Thanks. I have adjusted the font. I did not realize size 7 would be so large.
Thanks for the reply too. This Microsoft article explains that when two strings are compared, the strings are padded with trailing spaces first so that the lengths match.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply