I have one table for which I want to find all instances, where 0 is the last character in the row field. I tried this using two methods, and each of them returned different results.
This first query seemed to really return the correct answer
select * from icd where CHARINDEX('0',icd,LEN(icd)) =LEN(icd)
this one will not catch all the answers
select * from icd where PATINDEX('%0%',icd) = LEN(icd)
using
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
I found a dataset that CHARINDEX took that PATINDEX did not. I even did
update icd set ICD=RTRIM(icd)
Why PATINDEX leave several lines indiscriminately?
source share