且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

T-SQL LIKE 条件中的重复字符

更新时间:2023-02-06 07:40:57

您可以使用 not carat ^ 和 NOT LIKE 表达式执行此操作.

You can do this with the not carat ^, and a NOT LIKE expression.

所以你说,哪里不像非字母数字;) 这适用于标准数字 &字符:

So you say, where not like not non-alphanumeric ;) This works for standard numbers & characters:

declare @var as VARCHAR (150)
select @var = '123ABC'

if (@var NOT LIKE '%[^a-zA-Z0-9]%')
    print 'OK'
else
    print 'Not OK'

感谢 Martin 的整理提示,如果您希望将 ý 等字符视为非字母数字,请添加到 COLLATE 中,如下所示

Thanks Martin for the collation hint, if you want the characters like ý treated as non-alphanumeric add in the COLLATE as below

declare @var as VARCHAR (150)
select @var = '123ABCý'

if (@var NOT LIKE '%[^a-zA-Z0-9]%' COLLATE Latin1_General_BIN ) 
    print 'OK'
else
    print 'Not OK'