Solved

Is there a way to case sensitive DISTINCT query?

Posted on 2007-11-29
3
1,142 Views
Last Modified: 2011-10-03
Hi,
My database is set to be case insensitive.
Is there a way to case sensitive DISTINCT query?
i.e.
My table Employees has columns Name and Email
Name       Login
George   10 AM
Tom        10 AM
Tom        11 AM
Tom        12 PM
TOM      10 AM
TOM      11 AM
TOM      1PM

When i query select distinct name from Employess, the result set is
George, Tom as expected.

How can I query so that result set is George, Tom, TOM?

Thanks
Jamie
0
Comment
Question by:jamie_lynn
  • 2
3 Comments
 
LVL 18

Expert Comment

by:Jinesh Kamdar
ID: 20379923
What DB are you using?
0
 
LVL 5

Accepted Solution

by:
ursangel earned 500 total points
ID: 20380693
Im guesing its SQL server...
A default SQL Server installation is case insensitive, which means that SQL Server will not differentiate between upper and lower case characters/letters. By default SQL Server 2000 gets installed with case insensitive collation. You must change the collation of the server while installing, if you want case sensitiveness.
The work around for this is to convert the columns that need to be compared as Case sensitive into varbinary and do the comaprison.

select  distinct cast(a.name as varbinary(25))name into #Temp from employee a where
                  cast(a.name as varbinary(25)) in
                        (select distinct cast(b.name as varbinary(25))name  from employee b)  
Go

select cast(name as varchar(25)) name from #Temp
0
 
LVL 5

Expert Comment

by:ursangel
ID: 20380919
One easy way.

SELECT   distinct Name COLLATE Latin1_General_CS_AS
FROM      Employees
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Character matching different date formats for dates between 6 69
SYbase 4 43
error in my cursor 5 50
help restore my wordpress site made on WAMP 8 36
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question