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.
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.
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.
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.
Use a Unicode search string:
WHERE CONTRACTORNAME LIKE N'%ạ%'
Credit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With