Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - Searching string with international characters using LIKE clause

I have a field 'Description' which can have product descriptions with any unicode characters. If I search for a description which contains an international character, with a LIKE condition (word searched with does not have the international character) I get the following results:

Ex: GEWÜRZTRAMINER is one of the descriptions. When I do:

Select * from table where Description LIKE '%GEWURZTRAMINER%', it retrieves the entry.

When I do:

Select * from table where Description LIKE '%GEWURZ%', the entry is not retrieved.

(Note: the search condition does not include the Ü but has a U)

Is there a way around this so that I can retrieve with '%GEWURZ%' as well?

like image 569
Nikhil Avatar asked Feb 02 '26 06:02

Nikhil


2 Answers

For bog standard varchar, you'd have to coerce to a accent insensitive collation

Select 1 where 'GEWÜRZTRAMINER' COLLATE LATIN1_GENERAL_CI_AI LIKE '%GEWURZTRAMINER%'

There should be no difference between the calls though for the SQL you provided.

like image 83
gbn Avatar answered Feb 04 '26 19:02

gbn


It will depend on the collation order for the column. It should work if you use e.g. SQL_Latin1_General_CP1_CI_AI

like image 22
Joe Avatar answered Feb 04 '26 19:02

Joe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!