patindex(): Returns the starting position of the first occurrence of a pattern in a specified expression, or zeros if the pattern is not found, on all valid text and character data types.
函数用于取得符合通配符的字符在字符串中第一次出现的索引(Index), 如果没有找到返回0.
最近遇到这么个问题:在数据库中找出某一列中所有含有非汉字的记录:
select patindex('%[^吖-咗]%',ltrim(rtrim([yourColumn]))) > 0
找出某一列中所有含有汉字的记录:
select patindex('%[吖-咗]%',ltrim(rtrim([yourColumn]))) > 0
需要注意的是:
patindex函数不支持正则表达式(Regex),它的参数只是通配符(Wildcard Charact