简体   繁体   English

SQL 空格或空的通配符

[英]SQL Wildcards for space or nothing

I am using wildcards in a join statement to find when a specific phrase is contained in a text field.我在连接语句中使用通配符来查找特定短语何时包含在文本字段中。 Originally, I tried something like:最初,我尝试过类似的东西:

[Text Field] LIKE '%[^0-9A-Z]' + [Phrase] + '[^0-9A-Z]%'

However, this only gives me results that contain the phrase inside of the text field surrounded by spaces or special characters.但是,这只会给我包含文本字段内被空格或特殊字符包围的短语的结果。 Instead I need it to be when the phrase is surrounded by a leading or trailing space, or if the phrase is at the beginning or end of text field.相反,当短语被前导或尾随空格包围时,或者短语位于文本字段的开头或结尾时,我需要它。 Does anyone have any idea on how to accomplish this?有谁知道如何做到这一点? I have searched around to no avail.我四处搜寻无果。

Presumably, you are using SQL Server.据推测,您正在使用 SQL 服务器。 Just add spaces to the beginning and end of the column:只需在列的开头和结尾添加空格:

' ' + [Text Field] + ' ' LIKE '%[^0-9A-Z]' + [Phrase] + '[^0-9A-Z]%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM