我一直在查看下面复制的这段代码,它用于查找非ASCII字符...
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
它就是不能做同样的事情,是我缺少一些语法吗?这是不可能的吗?