SQL 服务器使用 LIKE 查找带重音的拉丁词

SQL Server find accented Latin word using LIKE

Table数据

----------------------------
jalapeño jam
----------------------------
jalapeño jams
----------------------------

查找数据有like 'jalapeñ'结果给成功

但是当我用 'jalapen' 查找时,它没有给出任何结果。

我的查询

SELECT TOP 50 Id,Name AS Keyword
FROM Keywords (NOLOCK)
WHERE Name like N'%jalapen%'`

您的专栏似乎使用了区分重音的排序规则。您需要使用 accent-insensitive 排序规则。您可以通过添加 COLLATE 关键字和适当的排序规则(例如 Latin1_General_100_CI_AI)在查询中强制执行此操作,例如:

SELECT TOP 50 Id,Name AS Keyword
FROM Keywords WITH (NOLOCK) -- at least add the "WITH", but best to not use at all
WHERE Name like N'%' + @Keyword + N'%' COLLATE Latin1_General_100_CI_AI;

在排序规则名称中,_AI表示"Accent INsensitive",就像_CI表示"Case INsensitive"。