我有一个表,我希望在其中找到字符串字段中0
最后一个字符的所有实例。我通过使用两种方法进行了尝试,它们都返回了不同的结果。
这第一个查询似乎实际上返回了正确的答案
select * from icd
where CHARINDEX('0',icd,LEN(icd)) =LEN(icd)
这个没有抓住所有的答案
select * from icd
where PATINDEX('%0%',icd) = LEN(icd)
使用
select t.ICD as theCharIndex,x.ICD as thePatIndex from
(
select * from icd
where CHARINDEX('0',icd,LEN(icd)) =LEN(icd)
) t
left join
(
select * from icd
where PATINDEX('%0%',icd) = LEN(icd)
) x on x.ICD=t.ICD
where x.ICD is null
我发现收集到的数据集CHARINDEX
没有PATINDEX
。我什至做了
update icd
set ICD=RTRIM(icd)
为什么会PATINDEX
不加选择地遗漏一些行?