Reputation: 47595
This works:
select Name
from Table
WHERE Name like '%[^0-9A-Za-z]%'
But now I need to add the dash character to the criteria as well.
Upvotes: 10
Views: 10945
Reputation: 16240
Unless it's part of a range the hyphen is not a special character in LIKE
patterns, so you can just add it to your pattern, e.g.:
select
[char]
from
(
select 'a' as 'char' union
select '-' union
select '$' union
select '7'
) dt
where
[char] like '%[^A-Za-z0-9-]%'
Upvotes: 8
Reputation: 22915
use
...ESCAPE '\'
e.g.
WHERE Name like '%[^0-9A-Za-z\-]%' ESCAPE '\'
to have the final "-" treated as a literal.
Upvotes: 16