如何在unicode字符串中使用'LIKE'语句?

时间:2022-08-29 20:15:34

I am trying to execute a query with unicode characters. I was able to execute the normal equality query by prepending N to the query (Eg: ..... WHERE column=N'exact_stringâ'). But that doesn't seem to work when I try to use LIKE. Any ideas on how to make this work?

我正在尝试使用unicode字符执行查询。我能够通过在查询前加N来执行正常的相等查询(例如:...... WHERE column =N'exact_stringâ')。但是,当我尝试使用LIKE时,这似乎不起作用。关于如何使这项工作的任何想法?

Sample query: SELECT * FROM t_sample WHERE t_column LIKE N'%â%'

示例查询:SELECT * FROM t_sample WHERE t_column LIKE N'%â%'

Also how can I know which encoding does the SQL Server use to store the nvarchar or nchar data type and what encoding it uses to show the query in SQL Editor?

另外,我如何知道SQL Server使用哪种编码来存储nvarchar或nchar数据类型以及它用于在SQL编辑器中显示查询的编码?

EDIT: My bad. This actually works. I have tried executing the query in a wrong window. But the upside of this is that I learned about Collation settings in SQL Server.

编辑:我的坏。这实际上有效。我试过在错误的窗口中执行查询。但这样做的好处是我了解了SQL Server中的Collat​​ion设置。

2 个解决方案

#1


2  

Make sure the collation on your table supports unicode.

确保表上的排序规则支持unicode。

#2


8  

Use a Unicode search string:

使用Unicode搜索字符串:

WHERE CONTRACTORNAME LIKE N'%ạ%'

Credit

#1


2  

Make sure the collation on your table supports unicode.

确保表上的排序规则支持unicode。

#2


8  

Use a Unicode search string:

使用Unicode搜索字符串:

WHERE CONTRACTORNAME LIKE N'%ạ%'

Credit