sqlsql-serversql-server-2012nvarcharthai

SQL WHERE clause does not match on columns with Latin and Thai characters


I'm cleaning up a SQL Server 2012 database which contains some nvarchar columns containing mixed character set data (Latin and Thai script). For example:

enter image description here

As I have a number of columns with the same TariffDescription text, I want to apply a translation using a simple UPDATE command. For example:

UPDATE Tariff.NationalTariff 
SET TariffDescription = 'Liquid.' 
WHERE TariffDescription = 'Thai description: - - ที่มีสภาพเหลว';

However, when I execute this command, SQL Server is not updating any rows. I confirmed that the problem is with the WHERE clause by attempting to do a simple select:

SELECT * 
FROM Tariff.NationalTariff 
WHERE TariffDescription = 'Thai description: - - ที่มีสภาพเหลว';

This query returns zero rows when I expected it to return around a hundred or so.

Note that I populated the WHERE clause string by copying and pasting from the Results table (using a query that does not rely on the TariffDescription column). I cannot type in Thai characters.

I have no idea why this is happening and my best guess is that it has something to do with mixing together character sets. Any ideas?


Solution

  • Place N before the literal text

       SELECT * FROM Tariff.NationalTariff WHERE TariffDescription = N'Thai description: - - ที่มีสภาพเหลว';