Solved

Is there a way to case sensitive DISTINCT query?

Posted on 2007-11-29
3
1,112 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction: I have seen many questions on EE and elsewhere, asking about how to find either gaps in lists of numbers (id field, usually) ranges of values or dates overlapping date ranges combined date ranges I thought it would be a good …
Creating and Managing Databases with phpMyAdmin in cPanel.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now