I want to be able to select only the field where a certain field contains both letters and numbers. for example:
Select [field1], [field2]
from [db1].[tabl
If you need it to contain both numerics and letters, and no other characters, I think you have to use 3 like clauses. One NOT LIKE
, as @gbn said, then 2 LIKE
s to ensure both character classes are represented:
select * from (select '123' union all select 'abc' union all select 'a2') t(Field)
where Field LIKE '%[0-9]%' and Field like '%[a-z]%'
AND Field NOT LIKE '%[^0-9a-z]%'
returns one row, with 'a2'
.
If it should only be letters followed by numbers, I'm thinking you might be able to achieve this with a further not like, again inspired by @gbn:
NOT LIKE '%[0-9]%[a-z]%'
But it is starting to look like a regex in CLR might be the preferred route.