In T-SQL, how would you check if a string contains two or more similar characters?
I have column contains mobile numbers of nvarchar which could be “5512111445”,”6612888445″ or hidden numbers like “5512zzz44x”
I have a search pattern entered by the user which could be “xx12yyy4zx” and i would like to return all the matched numbers to this pattern where x,y,z representing any number, but if it’s repeated it will representing the same number. the previous pattern for example should return all the listed numbers above.
xx are similar numbers like 55 or 66.. whereas xy are different numbers like 45 or 67..
How can this be done?
You could pivot each character in the mask and number into columns, and then group on mask alone followed by mask + number. In this method 5512111445 and 6612888445 do not match mask xx12yyy4yz because the y in mask does not map to a unique digit. However, mobile numbers 5512111415 and 6612888485 do match mask xx12yyy4yz, as does mobile number 5512zzz44x.
EDIT – Add a rule that no numeric @mobileNums digit can correspond to more than one alpha @mask character
EDIT – For
GROUP BY n, include the three remaining combinations of ISNUMERIC(n) and ISNUMERIC(m)EDIT – removing the eighth
UNION