gingerbreadboy
gingerbreadboy

Reputation: 7769

SQL WHERE clause for column all capitalized

table_beatles contains the following data in column name.

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.

Upvotes: 0

Views: 3870

Answers (3)

Edelcom
Edelcom

Reputation: 5058

SELECT * FROM table_beatles where UPPER(name) = name

Upvotes: -2

Rubens Farias
Rubens Farias

Reputation: 57956

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

Upvotes: 1

David M
David M

Reputation: 72870

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.

Upvotes: 9

Related Questions