For example, if I have this data:
CREATE TABLE FooBar ( Name varchar(16) )
INSERT FooBar SELECT 'test@test.com'
The following queries don’t return what I would expect:
SELECT * FROM FooBar WHERE Name = 'test@test.com ' -- Returns the row
SELECT * FROM FooBar WHERE Name LIKE 'test@test.com ' -- Nothing Returned
SELECT * FROM FooBar WHERE Name = ' test@test.com' -- Nothing Returned
Why does = (which I assume means exactly equals) with extra space at the end return data, while a LIKE does not?
Seing the standard it depends on padding (The ANSI standard requires padding for the character strings used in comparisons so that their lengths match before comparing them)
See also how SQL Server compares strings with trailing spaces