How to find rows that have a value that contains a lowercase letter

前端 未结 13 1415
醉梦人生
醉梦人生 2021-02-01 00:36

I\'m looking for an SQL query that gives me all rows where ColumnX contains any lowercase letter (e.g. \"1234aaaa5789\"). Same for uppercase.

相关标签:
13条回答
  • 2021-02-01 00:43
    SELECT * FROM my_table WHERE my_column = 'my string'
    COLLATE Latin1_General_CS_AS
    

    This would make a case sensitive search.


    EDIT

    As stated in kouton's comment here and tormuto's comment here whosoever faces problem with the below collation

    COLLATE Latin1_General_CS_AS
    

    should first check the default collation for their SQL server, their respective database and the column in question; and pass in the default collation with the query expression. List of collations can be found here.

    0 讨论(0)
  • 2021-02-01 00:48
    SELECT * FROM my_table 
    WHERE UPPER(some_field) != some_field
    

    This should work with funny characters like åäöøüæï. You might need to use a language-specific utf-8 collation for the table.

    0 讨论(0)
  • 2021-02-01 00:49
    SELECT * FROM Yourtable 
    WHERE UPPER([column_NAME]) COLLATE Latin1_General_CS_AS !=[Column_NAME]
    
    0 讨论(0)
  • 2021-02-01 00:50

    I have to add BINARY to the ColumnX, to get result as case sensitive

    SELECT * FROM MyTable WHERE BINARY(ColumnX) REGEXP '^[a-z]';
    
    0 讨论(0)
  • 2021-02-01 00:51

    I've done something like this to find out the lower cases.

    SELECT *
    FROM YourTable
      where BINARY_CHECKSUM(lower(ColumnName)) = BINARY_CHECKSUM(ColumnName)
    
    0 讨论(0)
  • 2021-02-01 00:53

    Logically speaking Rohit's solution should have worked, but it didn't. I think SQL Management Studio messed up when trying to optimize this.

    But by modifying the string before comparing them I was able to get the right results. This worked for me:

    SELECT [ExternalId]
    FROM [EquipmentSerialsMaster] where LOWER('0'+[ExternalId]) COLLATE Latin1_General_CS_AS != '0'+[ExternalId]
    
    0 讨论(0)
提交回复
热议问题