Link to home
Create AccountLog in
Avatar of tdeinzer2005
tdeinzer2005

asked on

case sensitivity in Transact-SQL statement

Is there a way to make a where clause in a query (executed from Query Analyzer) case sensitive.  For instance, if you wanted to find records based on how people entered a country name:

where country = 'usa'
where country = 'Usa'
where country = 'USA'

Normally, of course, these there queries would produce the same results.

Avatar of adwiseman
adwiseman

There is a server setting that can make the server case sensative.  But not an idividual query, I don't think.
Avatar of Scott Pletcher
I think if you cast both to varbinary you can get a case-sensitive match, although that prevents use of an index on that column (if you need a way around that, please let me know):

where cast(country as varbinary(100)) = cast('usa' as varbinary(100))



you should use case sensitive collation .

lets see... try this

select * from tblmember
where address1  COLLATE SQL_Latin1_General_CP1_CS_AS = 'usa'

by default collations are case insensitive such as SQL_Latin1_General_CP1_CI_AS (notice CI before AS which means case insensitive)... all you need to do is check the collation you have on the field and then apply similar one with CS in it.


few common ones are SQL_Latin1_General_CP1_CS_AS, Latin1_General_CP1_CS_AS, latin1_general_cs_as

Cheers
ASKER CERTIFIED SOLUTION
Avatar of J2811
J2811

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer