你可以使用PATINDEX
:
DECLARE @test table(col varchar(30));
INSERT INTO @test
SELECT * FROM (SELECT 'CLARK' UNION ALL SELECT 'KING' UNION ALL SELECT 'MILLER' UNION ALL SELECT 'SMITH, $800 .00' UNION ALL SELECT 'JONES, $2975.00' UNION ALL SELECT 'SCOTT, $3000.00' UNION ALL SELECT 'ADAMS, $1100.00' UNION ALL SELECT 'FORD, $3000.00' UNION ALL SELECT 'ALLEN30' UNION ALL SELECT 'WARD30' UNION ALL SELECT 'MARTIN30' UNION ALL SELECT 'BLAKE30' UNION ALL SELECT 'TURNER30' UNION ALL SELECT 'JAMES30')AS T(Spalte)
Patindex
返回指定表达式中模式第一次出现的起始位置。由于我使用了匹配任何非字母数字(^ 通配符 - 字符)的模式,因此仅返回仅包含字母数字字符(+空格)的记录:
SELECT col
FROM @test
WHERE PATINDEX('%[^a-zA-Z0-9 ]%',col) = 0
结果:
CLARK
KING
MILLER
ALLEN30
WARD30
MARTIN30
BLAKE30
TURNER30
JAMES30