Possible Duplicate:
SQL WHERE clause matching values with trailing spaces
When querying SQL Server (through Management Studio Express for what its worth), I've noticed that when querying a varchar
field it doesn't matter if you have some trailing whitespace in your criteria, it will still match.
The below matches matched
(so it ignores the trailing whitespace in the search criteria)
select top 10 * from sometable
where somecolumn = 'matched '
I've tried this on 2005 and 2012, same result.
Any ideas why this happens? Is it something to do with how varchar
are stored?