views:

228

answers:

1

I'd like to create a check constraint for a table in SQL 2008 which would allow A-Z characters (non case sensitive), numbers, hyphen (-), dot(.), space and underscore (_). Below is my current expression: ([company_code] not like '%[^A-Za-z0-9_ .+]%').

It fulfills all the above requirements except for hyphen. How could I make the expression allowing hyphen as well?

+1  A: 

You can use an ESCAPE clause:

not like  '%[^A-Za-z0-9_ .+\-]%' escape '\'

The character after the escape character will be matched literally.

Andomar