首页 > 解决方案 > 选择包含正方形 2 的字符串

问题描述

我想选择包含正方形 2 的行(这个 char '²')

我确实select myColumn from table where myColumn '%²%'
得到了包含“²”的列,但也得到了包含“2”的列。

我试过select myColumn from table where myColumn '%2%'了,我得到了同样的结果。

SQL Server 中有没有办法选择只包含正方形 2 字符的列?

标签: sql-server

解决方案


您必须使用正确的排序规则,Latin1_General_BIN例如。

declare @t table(t nvarchar(20))
insert into @t values('²'), ('2')
-- Will return only the row with the number.
select * from @t where t like N'%2%' collate Latin1_General_BIN
-- Will return only the row with square 2.
select * from @t where t like N'%²%' collate Latin1_General_BIN

推荐阅读