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
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