Case Sensitive String Comparison in SQL Server

SQL Server is installed with default “Collation” if it is not specified. You can check out your Database Server default “Collation” using this query.


SELECT SERVERPROPERTY ('Collation');


“SQL_Latin1_General_CP1_CI_AS” is the default “Collation” of SQL Server and this doesn’t support case sensitive String comparison. However, if you want to make case sensitive String comparison, you have two options left. Either alter the Column “Collation” to “SQL_Latin1_General_CP1_CS_AS” or add “Collate SQL_Latin1_General_CP1_CS_AS” at the end of query to perform case sensitive String comparison.


SELECT * FROM t_User WHERE User_Name = ‘User Name’ AND User_Password =’User Password’ Collate SQL_Latin1_General_CP1_CS_AS;

Thanks
A Rahim Khan

Advertisements
  1. wonderful information !!!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: