When I compared text like this:
'a' = 'a '
the result is True - but I was expecting it to be false.
Do you know why the result is true? And can I do something to solve this issue?
When I compared text like this:
'a' = 'a '
the result is True - but I was expecting it to be false.
Do you know why the result is true? And can I do something to solve this issue?
You can use DATALENGTH()
Example
SELECT * FROM TableName WHERE DATALENGT('a') = DATALENGTH('a ')
DATALENGT('a')
return the result as 1
and DATALENGTH('a ')
return the result as 2, includes the space text.
Please check the db<>fiddle
for reference.
The LIKE operator does not pad the trailing spaces:
SELECT * FROM basePath WHERE 'a' LIKE 'a '
More information can be found here: https://dba.stackexchange.com/questions/56876/sql-server-auto-trim-of-varchar-value-in-equal-comparison-but-not-like-compariso