I need to locate rows in a database table that have a field with an upper case value.
E.g.: select * from Cust where Surname like \'COnTAiNS UpPERcASE VaLUe
You could do something like this:
SELECT
CASE WHEN BINARY_CHECKSUM('yourStriNg') = BINARY_CHECKSUM(LOWER('yourStriNg'))
THEN 0
ELSE 1
END
....
Rest of SQL statement
Try this to extract only capital letter from given string value:
Declare @Val Varchar(100)
Set @Val='MicrosoftAsp.NeT4You'
--Return Val
Declare @RetCapWord varchar(100)
Set @RetCapWord=''
;WITH CTE AS
(
Select @Val As oldVal,1 As TotalLen,SUBSTRING(@Val,1,1) As newVal,
ASCII(SUBSTRING(@Val,1,1)) As AsciVal
UNION ALL
Select oldVal,TotalLen+1 As TotalLen,
substring(@Val,TotalLen+1,1) As newVal,
ASCII(SUBSTRING(@Val,TotalLen+1,1)) As AsciVal
From CTE
where CTE.TotalLen<=LEN(@Val)
)
Select @RetCapWord=@RetCapWord+newVal
From CTE
Inner Join master..spt_values as m on CTE.AsciVal=m.number and CTE.AsciVal between 65 and 90
Select @RetCapWord
You can do a binary comparison using:
select *
from Cust
where cast(Surname as varbinary(120)) != cast(lower(Surname) as varbinary(120))
Another way
SELECT *
FROM Cust
WHERE Surname NOT LIKE '%[^A-Z]%' COLLATE Latin1_General_BIN