【问题标题】:Using emails in like statements not working [closed]在类似的声明中使用电子邮件不起作用[关闭]
【发布时间】:2020-11-09 19:30:34
【问题描述】:

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

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

以下不返回任何结果:

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

但我没有得到任何结果。

【问题讨论】:

标签: sql sql-server tsql sql-like


【解决方案1】:

您的示例数据似乎有效:

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)

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

【讨论】:

    猜你喜欢
    • 2013-09-20
    • 2014-07-05
    • 1970-01-01
    • 2021-11-24
    • 2022-09-29
    • 2021-02-12
    • 1970-01-01
    • 2020-11-04
    • 1970-01-01
    相关资源
    最近更新 更多