Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 29th, 2005, 04:31 AM
Authorized User
 
Join Date: Nov 2005
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to x_ray
Default Case Senesitive matching

hi all,
i want to ask if there is a way to do a case sensitive search in SQL queries, for example
Select * from usrs where pwd='somevalue'// is there any fucntion i can use here to force a case sensitive match
thanks

 
Old November 29th, 2005, 10:34 AM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes use COLLATE SQL_Latin1_General_CP1_CS_AS, take a look at the following example

create TABLE dbo.Customers

(
            CustID char(8) NOT NULL ,
            CustPassword varchar(15) NOT NULL,
            CustName varchar(25) NOT NULL,
            CustEmail varchar(60) NOT NULL,
            CustAddress varchar(100) NOT NULL
)

GO


INSERT INTO dbo.Customers VALUES('USA00001', 'TheUnbreakable', 'John', '[email protected]', '10932,Bigge Rd., Menlo Park, CA')
INSERT INTO dbo.Customers VALUES('USa00001', 'ABCxyz012789', 'Heather', '[email protected]', '18 Broadway Av. San Francisco, CA')
INSERT INTO dbo.Customers VALUES('EUR00001', 'MagicNSparkle', 'Vyas', '[email protected]', '18 Grove Mead, Herts, AL09 7JK, UK')
INSERT INTO dbo.Customers VALUES('ASA00001', 'aAbBcCXyZ', 'Franklin', '[email protected]', '22 Main Street, Singapore')
INSERT INTO dbo.Customers VALUES('OZ000001', 'DOWNundah', 'Steve', '[email protected]', '321, Cricket Way, Melbourne, Australia')

SELECT *
            FROM dbo.Customers
            WHERE CustID = 'USA00001' COLLATE SQL_Latin1_General_CP1_CS_AS

SELECT *
            FROM dbo.Customers
            WHERE CustID = 'USA00001'

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/
 
Old November 29th, 2005, 06:19 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

As I recall there is also a setting to turn case sensitivity on at the database level but its turned off as default. Might also want to check on this if you don't want to do the stuff with Collate and specify languages. But I may be thinking of a different RDBMS so verify it for yourself in your server settings.

 
Old December 3rd, 2005, 07:48 AM
Authorized User
 
Join Date: Nov 2005
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to x_ray
Default

10x guys for the help it has been a pleasure working with you, wish you both good luck

 
Old January 6th, 2006, 06:10 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

Hi,

Either you can go for COLLATION for case sensitive match other wise the better and handy way is to use ASCII value comparison. This aproach doesn't change your SQL Collation and transparent to other users. See ASCII ndton in T-SQL.

Hope you got the idea.

B. Anant
 
Old January 6th, 2006, 03:49 PM
Authorized User
 
Join Date: Nov 2005
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to x_ray
Default

thanks B. Anant for your extra information, although the above replies helped a lot, however extra information is not bad, but could you please give an example?
also what does ndton mean?

 
Old January 6th, 2006, 06:56 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
Default

Sometimes an example is worth a 1000 words

Use Northwind
GO
Select SERVERPROPERTY(N'Collation')
/*
SQL_Latin1_General_CP1_CI_AS -- the collation I am using
SQL_Latin1_General_CP1_CS_AS -- the collation I will use for the comparison
*/

--Setup Data for Example
UPDATE dbo.Customers SET ContactTitle = 'OWNer'
    WHERE CustomerID = 'ANATR'

--Case Insensitive Search
SELECT CustomerID, ContactTitle
FROM dbo.customers
WHERE contactTitle = 'OWNer'

--Case Sensitive Search -- that won't find our test data
SELECT CustomerID, ContactTitle
FROM dbo.customers
WHERE contactTitle COLLATE SQL_Latin1_General_CP1_CS_AS = 'Owner'

--Case Sensitive Search -- that will find our test data
SELECT CustomerID, ContactTitle
FROM dbo.customers
WHERE contactTitle COLLATE SQL_Latin1_General_CP1_CS_AS = 'OWNer'

David Lundell
Principal Consultant and Trainer
www.mutuallybeneficial.com
 
Old January 7th, 2006, 04:02 AM
Authorized User
 
Join Date: Nov 2005
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to x_ray
Default

it is true that an example worth 1000 words especially if it is perfect, i will try it and tell tell you the results(although sure that it will work fine),Anyway thanks David for your great help, that twice you came for my rescue and i appreciate that.


 
Old January 7th, 2006, 02:34 PM
Authorized User
 
Join Date: Sep 2005
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Anantsharma,
ASCII works only 1 character at a time meaning select ascii('ab'),ascii('ac') returns 97 in both cases, you would have to loop thru the whole string
And the ASCII character set only has 255 characters what about non ASCII characters?

“I sense many useless updates in you... Useless updates lead to fragmentation... Fragmentation leads to downtime...Downtime leads to suffering..Fragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" -- http://sqlservercode.blogspot.com/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Matching two strings jamie_t VB How-To 0 October 12th, 2005 03:40 AM
PHP Pattern Matching joanncae BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 May 17th, 2004 04:52 PM
Finding a matching value Morry Excel VBA 2 March 26th, 2004 05:32 AM
search string either Upper case or lower case rylemer Beginning VB 6 3 March 24th, 2004 04:23 PM
Check Case in a Case-Insensitive DB nbryson SQL Language 1 January 23rd, 2004 07:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.