February 20, 2006 at 6:33 am
Hi All,
I'm trying to achieve a functionality by comparing an empty string with a non-empty string (string containing space characters). SQL server treats this kind of comparison to be equal.
Sample code:
IF('' = ' ')
Print 'Equal'
Else
Print 'Not Equal'
Executing the above SQL code in SQL query analyzer will print 'Equal' instead of 'Not Equal'. Can anyone tell whether this is due to some server setting or do we have any workarond to solve this problem.
Thanks,
John.
February 20, 2006 at 7:32 am
Try replacing your = with LIKE. It's better to use the LIKE indicator when comparing string information. This should give you your expected results.
February 21, 2006 at 10:50 am
SQL Server 2000 follows the ANSI SQL standards when comparing strings of different lengths, the shorter string is padded with blanks and then compared. So SQL Server 2000 is correct in saying that an empty string equals a string of 1 blank.
February 23, 2006 at 1:31 am
Got it. Thanks for the reply.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply