Hello,
I want to know if SQL is not case sensitive then how can i get particular data.
such as:-
In "EmployeeDetail" table there a "employee1" whose password is "NeWdElHi"
and other "employee2" whose password is "newdelhi" and
if i want data according to "Password" field and want result of "employee1"
so how can i get desired result?
Because if we write query that "select EmpName from EmployeeDetail where password='NeWdElHi' "
i get both values.
Thanks
Prashant Singh
Loading
Prashant SinghPosted Sep 17, 2012, 3:08 AM
Adil AnsariPosted Sep 13, 2012, 9:09 AM
DECLARE @CustID char(8), @CustPassword varchar(15)
SET @CustID = 'usa00001' SET @CustPassword = 'theunbreakable'
IF EXISTS (
SELECT 1 FROM dbo.Customers WHERE
BINARY_CHECKSUM(CustID) = BINARY_CHECKSUM(@CustID)
AND
BINARY_CHECKSUM(CustPassword) = BINARY_CHECKSUM(@CustPassword) )
BEGIN
PRINT 'Customer Found!'
END
ELSE
BEGIN
PRINT 'Invalid Customer ID or Password!'
END
GO
>>>>Way 2
Case Sensitive SQL Query Search
If Column1 of Table1 has following values 'CaseSearch, casesearch, CASESEARCH, CaSeSeArCh', following statement will return you all the four records.
SELECT Column1
FROM Table1
WHERE Column1 = 'casesearch'
To make the query case sensitive and retrieve only one record ("casesearch") from above query, the collation of the query needs to be changed as follows.
SELECT Column1
FROM Table1
WHERE Column1 COLLATE Latin1_General_CS_AS = 'casesearch'
Adding COLLATE Latin1_General_CS_AS makes the search case sensitive.
Default Collation of the SQL Server installation SQL_Latin1_General_CP1_CI_AS is not case sensitive.
To change the collation of the any column for any table permanently run following query.
ALTER TABLE Table1
ALTER COLUMN Column1 VARCHAR(20)
COLLATE Latin1_General_CS_AS
To know the collation of the column for any table run following Stored Procedure.
EXEC sp_help DatabaseName
Second results set above script will return you collation of database DatabaseName.
Reference : Pinal Dave (http://blog.SQLAuthority.com)
Prashant SinghPosted Sep 13, 2012, 7:38 AM
nallyaPosted Sep 13, 2012, 7:34 AM
ex:SELECT EmpName FROM Persons
WHERE Name='employee1'
AND password='NeWdElHi'