Sometimes we will find another query and you want to see different results, such as looking at the data table is to have value, but this time in accordance with the values to query how also can not find that this is probably some of the time special characters in mischief. For example, the following:
--测试数据
if not object_id(N'Tempdb..#T') is null
drop table #T
Go
Create table #T([col] nvarchar(22))
Insert #T
select N'小明
'
Go
--测试数据结束
Select * from #T WHERE col='小明'
The result is nothing to search
This is because the table contains data inserted in the carriage return, line and other special characters, so finding data, usually we may encounter other special characters:
--CHAR(9)tab \t
--CHAR(10) 换行 \r
--CHAR(13) 回车 \n
So we need to see these special special characters special treatment
--测试数据
if not object_id(N'Tempdb..#T') is null
drop table #T
Go
Create table #T([col] nvarchar(22))
Insert #T
select N'小明
'
Go
--测试数据结束
SELECT
*
FROM
#T
WHERE
REPLACE(REPLACE(REPLACE(col, CHAR(9), ''), CHAR(10), ''), CHAR(13), '') = '小明';
Can be replaced, of course, there may be characters such as spaces, directly or replaced by a function or the like can be treated RTRIM.