Possible Duplicate:
Using regular expression within a stored procedure
I need to validate a string, which should not contain contain lower case letters and Special Symbols. I have used below query, using this I’m able to find special symbols and unable to find lower case. Please suggest the best way.
DECLARE @InvNum VARCHAR(256);
SET @InvNum='abcACB123'
IF (@InvNum LIKE '%[^A-Z0-9]%')
BEGIN
Print 'Enter valid Invoice #, Special characters and Lowercase Letters are not allowed'
END
ELSE
BEGIN
Print 'Validation Success'
END
HalfTrackMindMan almost had it right (and does for the sample data), but unfortunately, character ranges always expand out to include lowercase letters (so
bcABC123would pass his validation):(
[A-Z]expands out asAbBcCdDeEf...zZ)Which collation to use is a matter of preference – either a binary collation, or one that is Case Sensitive (
_CS) and Accent Sensitive (_AS) will be suitable.