Tuesday, 23 February 2010

Trailing blanks

Following on from my post on 29th December 2008 on the LEN() function gotcha:

When comparing string values for equality, trailing blanks are ignored.
i.e. 'xyz' = 'xyz ' is true

However, rather than using the = operator, the LIKE operator will give a correct result
i.e. 'xyz' LIKE 'xyz ' is false

e.g.
IF ('xyz' = 'xyz ')
PRINT '= That shouldn''t work!'

IF ('xyz' LIKE 'xyz ')
PRINT 'LIKE That shouldn''t work!'