Suppose we create a table as follows:
create table my_table (
id int,
city nvarchar(256) collate Chinese_Hong_Kong_Stroke_90_CI_AS)
INSERT INTO my_table (id, city)
VALUES (1, 'Shanghai');
INSERT INTO my_table (id, city)
VALUES (2, 'Shandong');
INSERT INTO my_table (id, city)
VALUES (3, 'Shanxi');
INSERT INTO my_table (id, city)
VALUES (4, 'Shaanxi');
There are now four records in my_table:
id city
1 Shanghai
2 Shandong
3 Shanxi
4 Shaanxi
The following SQL queries return the same number. How to avoid this error?
select top 1 id from my_table order by DIFFERENCE(city, 'Shanghai') desc
select top 1 id from my_table order by DIFFERENCE(city, 'Shandong') desc
Another problem:
select top 1 id from my_table order by DIFFERENCE(city, 'Shannxi') desc
Returns 3 when the correct answer should be 4.