views:

83

answers:

3

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.

A: 
 SELECT * FROM table_beatles where UPPER(name) = name
Edelcom
do you tried? doesn't works here
Rubens Farias
@Rubens - see my answer for why...
David M
yes, I saw it, ty =)
Rubens Farias
Yes, used it last week in some project on a database set up by other persons. Must have been a case sensitive collation there.
Edelcom
+9  A: 

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.

David M
Is should have worked that out in about 2 seconds :\ Cheers :)
runrunraygun
+1  A: 

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

Rubens Farias