Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Exact comparison

Author  Topic 

mohdrashid
Starting Member

23 Posts

Posted - 2005-06-02 : 05:40:54
hi,
if i have the following records:

col1
abc
Abc
aBc
abC
ABC

doing a select with a where col1 = 'abC' will return me all the rows in the above table.
I would like it to return only the fourth row.
how to do this?

thanks in advance
rashid

AndyB13
Aged Yak Warrior

583 Posts

Posted - 2005-06-02 : 06:49:34
You could change the collation of the column to Case Sensitive

Example:

CREATE TABLE #MyTemp(Col1 varchar(3)) --Using My Default Collation
GO
INSERT #MyTemp(Col1)
SELECT 'abc' UNION ALL
SELECT 'Abc' UNION ALL
SELECT 'aBc' UNION ALL
SELECT 'abC' UNION ALL
SELECT 'ABC'
GO

SELECT *
FROM #MyTemp
WHERE Col1 = 'abC' --All records will be returned
GO

ALTER TABLE #MyTemp ALTER COLUMN Col1
varchar(3)COLLATE Latin1_General_CS_AS --CS bit = Case Sensitive
GO

SELECT *
FROM #MyTemp
WHERE Col1 = 'abC' --Only 1 record this time
GO

DROP TABLE #MyTemp


Andy

Beauty is in the eyes of the beerholder
Go to Top of Page
   

- Advertisement -