Thursday, November 16, 2006

Case sensitive query in Sql Server

Often it is needed that you need to search by tag directly from sql server or let's say you want to verify password against db(though i do it with hash matching). The most coolest way of doing is to add an "COLLATE SQL_Latin1_General_CP1_CS_AS" clause in your where statement.

For example,

SELECT *
FROM Eco_Tags
where [Title] = N'Fun' COLLATE SQL_Latin1_General_CP1_CS_AS

This will make sure that if there 'Fun' and 'fun' tags, it will only get the 'Fun' ones'.

No comments: