Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Beginner
Apr 17, 2007

Workaround for the SQL DISTINCT Clause

The SQL DISTINCT clause isn't case sensitive, which means that your query might end up pulling records with different cases.

A simple fix for this is to use the COLLATE clause in conjunction with the DISTINCT clause.

Use sql_latin1_general_cp1_ci_ai for case sensitive distinct clause:


a) CASE INSENSITIVE DISTINCT CLAUSE
SELECT DISTINCT (Item) COLLATE sql_latin1_general_cp1_cs_as
    FROM (
           SELECT  'a' item
 	   UNION ALL SELECT  'A'
	 )items

b) CASE SENSITIVE DISTINCT CLAUSE
SELECT DISTINCT (Item) COLLATE sql_latin1_general_cp1_ci_ai
    FROM (
           SELECT  'a' item
	   UNION ALL SELECT  'A'
	 ) items
Srinath MS
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap