如何在SQL Server中执行不区分重音的比较(例如è,é,ê和ë)? [英] How do I perform an accent insensitive compare (e with è, é, ê and ë) in SQL Server?
问题描述
我想比较SQL中的两个varchar,一个类似于 Cafe
,另一个类似于Café
SQL中有没有一种方法可以比较两个值。例如:
I'm looking to compare two varchars in SQL, one would be something like Cafe
and the other Café
is there a way in SQL that will allow the two values to be compared. For instance:
SELECT *
FROM Venue
WHERE Name Like '%cafe%'
因此,如果有一个名称为 Big BobsCaféExtraordinaire的场地
是否将其包含在结果集中?
So if there is a venue with the name Big Bobs Café Extraordinaire
it would be included in the result set?
推荐答案
强制使用不区分重音的排序规则
Coerce to an accent insensitive collation
您还需要确保两者如果要与表变量或临时表varchar列进行比较,则具有相同的排序规则以避免错误或进一步强制。
You'll also need to ensure both side have the same collation to avoid errors or further coercions if you want to compare against a table variable or temp table varchar column
,因为常量值将具有数据库的排序规则更新:仅适用于局部变量,不适用于常量,不适用,甚至不适用
and because the constant value will have the collation of the database Update: only for local variables, not for constants nope, not even then
SELECT *
FROM Venue
WHERE
Name COLLATE Latin1_general_CI_AI Like '%cafe%' COLLATE Latin1_general_CI_AI
这篇关于如何在SQL Server中执行不区分重音的比较(例如è,é,ê和ë)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!