我一直在看查找非 ASCII 字符的查询 https://stackoverflow.com/a/3917698/241211,转载如下……
select line,
patindex('%[^ !-~]%' COLLATE Latin1_General_BIN, Line) as [Position],
substring(Line, patindex('%[^ !-~]%' COLLATE Latin1_General_BIN, Line), 1) as [InvalidCharacter],
ascii(substring(line, patindex('%[^ !-~]%' COLLATE Latin1_General_BIN, Line), 1)) as [ASCIICode]
from staging.APARMRE1
where patindex('%[^ !-~]%' COLLATE Latin1_General_BIN, Line) > 0
...我突然想到我想声明一个变量'%[^ !-~]%' COLLATE Latin1_General_BIN
而不是每次都写出来,但是
declare @regex varchar(20) = '%[^ !-~]%' COLLATE Latin1_General_BIN;
select line,
patindex(@regex, Line) as [Position],
substring(Line, patindex(@regex, Line), 1) as [InvalidCharacter],
ascii(substring(line, patindex(@regex, Line), 1)) as [ASCIICode]
from staging.APARMRE1
where patindex(@regex, Line) > 0
只是不做同样的事情。我只是缺少一些语法吗?难道不可能吗?