Solved

Is there a way to case sensitive DISTINCT query?

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL anywhere 11 databases 1 82
Need a replacement data type in Oracle 6 77
SQL Query 34 99
Server configuration for MS Access - SQL Server app 8 72
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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…

810 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