在 like 语句中使用电子邮件不起作用

Using emails in like statements not working

搜索邮件时需要转义字符吗?我在主题列中有以下值:

XX Operation <operation@xxx.com>,Info XX<info@xxx.com>

以下没有 return 任何结果:

select top 10 * from messages where subject like '%operation@xxx.com%'

但是我没有得到结果。

您的示例数据似乎有效:

DECLARE @A VARCHAR(MAX) = 'XX Operation operation@xxx.com,Info XXinfo@xxx.com'

SELECT IIF(@A like '%operation@xxx.com%', 1, 0); -- give 1

. 不是 wildcard 字符,不需要转义。我将首先检查您的数据库的排序规则,然后是您的专栏。例如,以下不匹配:

DECLARE @A VARCHAR(MAX) = 'XX Operation operation@xxx.com,Info XXinfo@xxx.com'

SELECT IIF(@A like '%Operation@xxx.com%' COLLATE Latin1_General_CS_AS , 1, 0)

问题是由隐藏字符引起的。