Link to home
Start Free TrialLog in
Avatar of Valleriani
VallerianiFlag for Sweden

asked on

MS-SQL -- PATINDEX and REGEX

Trying to get a delete query that only keeps lines that have
a-z
A-Z
0-9
@-._

delete FROM [xxx] WHERE (PATINDEX('%[^a-zA-Z0-9@.-_]%',email) > 0)


Is the query I have but does not seem to fully work with the extra characters and scrubs them out if there is a character like '-' in them. Any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this:

delete FROM [xxx] WHERE (PATINDEX('%[^,a-z,A-Z,0-9,@,.,-,_]%',email) > 0)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Valleriani

ASKER

Putting the dash in the end seemed to help, thanks!