Locate upper case characters in SQL Server database field

前端 未结 4 480
猫巷女王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:26

    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

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2021-01-18 12:48

    You can do a binary comparison using:

    select *
    from Cust
    where cast(Surname as varbinary(120)) != cast(lower(Surname) as varbinary(120))
    
    0 讨论(0)
  • 2021-01-18 12:51

    Another way

    SELECT *
    FROM Cust
    WHERE Surname NOT LIKE '%[^A-Z]%' COLLATE Latin1_General_BIN
    
    0 讨论(0)
提交回复
热议问题