When comparing strings in SQL Server if the end of the string is a space then SQL Server ignores those spaces and compares them directly.
declare
@a
nvarchar(
50
);set
@a
=N
‘happycat1988‘
declare
@b
nvarchar(
50
);set
@b
=N
‘happycat1988 ‘
①: "= The trailing space will be ignored to return true"
if
(
@a
=
@b
)
select
‘True‘
as 直接等号比较
else
select
‘False‘
as 直接等号比较
②: "Like will return false"
if
(
@a
like
@b
)
select
‘True‘
as like比较
else
select
‘False‘
as like比较
③: The Len function also ignores the trailing spaces, but Datalength does not "④:" In the SELECT statement also ignores spaces "select * from Sysc_user where user_code like ' 000065 ' this statement will query out User_c Ode entries with spaces after 000065 and 000065 are added. If you are using User_code to associate with other tables. May cause lazy loading. Original Digest from https://www.2cto.com/database/201509/441544.html
A string in SQL Server with spaces at the end of the comparison