How to check for special characters?????
Can anyone white a query that checks to see if a variable contains special characters; except for hyphens, periods, and accents?
August 21st, 2015 10:04am
Sure, you just need to define your special characters list.
DECLARE @specials TABLE (char CHAR(1)) INSERT INTO @specials (char) VALUES ('`'),('~'),('!'),('@'),('#'),('$'),('%'),('^'),('&'),('*'),('('),(')'),('-'),('_'),('+'),('='),('{'),('['),(']'),('}'),(':'),(';'),('"'),(''''),('<'),('>'),('?'),(','),('.'),('/'),('?') DECLARE @table TABLE (value VARCHAR(50)) INSERT INTO @table (value) VALUES ('hfkdhfdfdfhds'),('4vfgdfgfgf'),('GT&%^&*G') SELECT value, SUM(CASE WHEN CHARINDEX(char,value) > 1 THEN 1 ELSE 0 END) AS specials FROM @table CROSS APPLY @specials GROUP BY value
Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 10:15am
How do you come up with this stuff Patrick???
Amazing!!
August 21st, 2015 11:16am
10 years, 4 companies, 3 countries and many database systems causes you to learn to think out of the box :)
Free Windows Admin Tool Kit Click here and download it now
August 21st, 2015 11:49am