tags:

views:

74

answers:

3

How to detect if a string contains special characters like #,$,^,&,*,@,! etc in SQL server 2005?

A: 

In postgresql you can use regular expressions in WHERE clause. Check http://www.postgresql.org/docs/8.4/static/functions-matching.html

MySQL has something simmilar: http://dev.mysql.com/doc/refman/5.5/en/regexp.html

skyman
+4  A: 
SELECT * FROM tableName WHERE columnName LIKE "%#%" OR columnName LIKE "%$%" OR (etc.)
Brendan Long
+1 : for etc. ;)
Manish
+4  A: 

Assuming SQL Server:

e.g. if you class special characters as anything NOT alphanumeric:

DECLARE @MyString VARCHAR(100)
SET @MyString = 'adgkjb$'

IF (@MyString LIKE '%[^a-zA-Z0-9]%')
    PRINT 'Contains "special" characters'
ELSE
    PRINT 'Does not contain "special" characters'

Just add to other characters you don't class as special, inside the square brackets

AdaTheDev