SQL:返回包含一个单词的记录,其中最后一个字母是除K以外的任何数字

Son*_*wal 1 sql sql-server ssms wildcard

假设我有一个表,其中包含名为“ Query”的列。我必须显示该列中的字符串已使用noloc而不是的记录nolock。请注意,noloc可以在/之前)或后面加上空格,等等。我只需要noloc除nolock 之前和之后具有任何内容的所有记录。有没有办法在SQL中做到这一点?

我试过了:

select * from table1
where Query LIKE '%noloc%'
Run Code Online (Sandbox Code Playgroud)

但这包括包含的查询nolock。我尝试了上述各种变化,例如在前后放置空格,%但是没有一个满足所有条件。

Aja*_*ran 5

您可以在where子句中使用这两个条件

select * from table1
where Query LIKE '%noloc%' and Query NOT LIKE '%nolock%'
Run Code Online (Sandbox Code Playgroud)