Skip to main content

Posts

Showing posts from August, 2012

COLLATE...!!! CASE INSENSITIVE TO CASE SENSITIVE DATA

I have a table called TEMP and I have inserted values as shown below. We can see word 'Dhinakaran' is written in different formats as 4 records here. CREATE TABLE TEMP ( ID INT , NAME VARCHAR ( 100 )) INSERT INTO TEMP ( ID , NAME ) VALUES ( 1 , 'DHINAKARAN' ), ( 2 , 'dhINAKaRAN' ), ( 3 , 'dhinakaran' ), ( 4 , 'DHinakaRAN' ) SELECT * FROM TEMP  If I wanted to select only 'dhinakaran',  (3rd record here), Then my Query  SELECT * FROM TEMP WHERE NAME = 'dhinakaran' will fail to return 3rd row. The output of the actual query will be as by default while installing, SQL Server will take sentences as Case Insensitive. So we can overcome this problem by using COLLATE. COLLATE is implemented as follows in our Select Statement. SELECT * FROM  TEMP WHERE NAME COLLATE  Latin1_General_CS_AS = 'dhinakaran'   Adding COLLATE Latin