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.
where country = 'usa'
where country = 'Usa'
where country = 'USA'
Normally, of course, these there queries would produce the same results.
There is a server setting that can make the server case sensative. But not an idividual query, I don't think.
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))
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
lets see... try this
select * from tblmember
where address1 COLLATE SQL_Latin1_General_CP1_CS_
by default collations are case insensitive such as SQL_Latin1_General_CP1_CI_
few common ones are SQL_Latin1_General_CP1_CS_
Cheers
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.