I am attempting to search a column that contains alphanumeric ids in it but want to write a query that returns records with letters and numbers but not one or the other.
i.e Acceptable: jjk44kndkfndFF
i.e Not acceptable: 223232323232 or aajnfdskDFdd
So far I have:
where PATINDEX('%[^a-zA-Z0-9 ]%',columnInQuestion)
This returns all alphanumeric records. Any direction appreciated
I think you need three predicates in the WHERE clause:
WHERE (columnInQuestion NOT LIKE '%[^a-zA-Z0-9]%') AND
(PATINDEX('%[a-zA-Z]%', columnInQuestion) <> 0) AND
(PATINDEX('%[0-9]%', columnInQuestion) <> 0)
(columnInQuestion NOT LIKE '%[^a-zA-Z0-9]%') is true if columnInQuestion contains only alphanumeric characters(PATINDEX('%[a-zA-Z]%', columnInQuestion) <> 0) is true if there is at least one alphabetic character in columnInQuestion(PATINDEX('%[0-9]%', columnInQuestion) <> 0) is true if there is at least one numeric character in columnInQuestionIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With