Locate upper case characters in SQL Server database field

前端 未结 4 481
猫巷女王i
猫巷女王i 2021-01-18 12:06

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         


        
4条回答
  •  孤街浪徒
    2021-01-18 12:35

    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
    

提交回复
热议问题