Sunday, 8 July 2012

SQL - check if a string has uppercase / lowercase characters


DECLARE @myString NVARCHAR(200) -- The length of the NVARCHAR is mandatory, otherwise it is not clear why but it is not working
SET @myString = 'ExTremeDev.blogSpot.com23'

IF @myString = LOWER(@myString) COLLATE Latin1_General_CS_AI
BEGIN
  PRINT '- The string must contain at least one uppercase character.'
END

IF @myString = UPPER(@myString) COLLATE Latin1_General_CS_AI
BEGIN
  PRINT '- The string must contain at least one lowercase character.'
END

IF PATINDEX('%[0-9]%',@myString) = 0
BEGIN
  PRINT '- The string must contain at least one numeric character.'
END

No comments:

Post a Comment