开发者

SQL WHERE clause for column all capitalized

开发者 https://www.devze.com 2022-12-17 14:25 出处:网络
table_beatles contains the following data in column name. John PAUL george RINGO In MS-SQL is there anyway to get any item which is all caps? eg

table_beatles contains the following data in column name.

  • John
  • PAUL
  • george
  • RINGO

In MS-SQL is there anyway to get any item which is all caps? eg

开发者_如何转开发
SELECT * FROM table_beatles where name is (AllCaps SYNTAX HERE)

to return PAUL and RINGO.


How you do this depends on the collation used. If you have a case insensitive collation, you are asking SQL to treat lower and upper case the same. So you may need to do this:

SELECT  *
FROM    table_beatles
WHERE   UPPER(name) COLLATE Latin1_General_CS_AS
             = name COLLATE Latin1_General_CS_AS

This forces SQL to use a case sensitive (CS) comparison for the equality check. If you already have a case sensitive collation, then you can omit the two COLLATE parts of this. But given you've asked the question, I'm guessing you haven't.


You want to do a case sensitive search. There are many methods explained here: Case sensitive search in SQL Server queries


SELECT * FROM table_beatles where UPPER(name) = name
0

精彩评论

暂无评论...
验证码 换一张
取 消