How to use 'LIKE' statement with unicode strings?

寵の児 提交于 2019-11-28 07:38:04

问题


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?

Sample query: 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?

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.


回答1:


Make sure the collation on your table supports unicode.




回答2:


Use a Unicode search string:

WHERE CONTRACTORNAME LIKE N'%ạ%'

Credit



来源:https://stackoverflow.com/questions/4251765/how-to-use-like-statement-with-unicode-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!