Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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_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.

like image 395
rkg Avatar asked Nov 23 '10 00:11

rkg


People also ask

What does a Unicode string look like?

Encodings. To summarize the previous section: a Unicode string is a sequence of code points, which are numbers from 0 through 0x10FFFF (1,114,111 decimal). This sequence of code points needs to be represented in memory as a set of code units, and code units are then mapped to 8-bit bytes.

What does like %% mean in SQL?

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.

How do you use like wildcard?

You can use the wildcard pattern matching characters as literal characters. To use a wildcard character as a literal character, enclose the wildcard character in brackets. The following table shows several examples of using the LIKE keyword and the [ ] wildcard characters.


1 Answers

Use a Unicode search string:

WHERE CONTRACTORNAME LIKE N'%ạ%'

Credit

like image 189
Shimmy Weitzhandler Avatar answered Nov 15 '22 16:11

Shimmy Weitzhandler