Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
779 views
in Technique[技术] by (71.8m points)

sql - How to use 'LIKE' statement with unicode strings?

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_stringa'). 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'%a%'

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use a Unicode search string:

WHERE CONTRACTORNAME LIKE N'%?%'

Credit


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...