Unix Technical Forum

Sort Order and case sensitivity

This is a discussion on Sort Order and case sensitivity within the SQL Server forums, part of the Microsoft SQL Server category; --> I have a query which filters records containing uppercase and Lowercase i.e. Smith and SMITH, Henderson and HENDERSON etc. ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:04 PM
Steve
 
Posts: n/a
Default Sort Order and case sensitivity

I have a query which filters records containing uppercase and
Lowercase i.e.

Smith and SMITH, Henderson and HENDERSON etc.

Is there a way that I can filter only those records that contain the
first uppercase letter and the remaining lowercase letters for my
query i.e. Smith , HENDERSON etc.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 08:05 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Sort Order and case sensitivity

Steve (murras68@hotmail.com) writes:
> I have a query which filters records containing uppercase and
> Lowercase i.e.
>
> Smith and SMITH, Henderson and HENDERSON etc.
>
> Is there a way that I can filter only those records that contain the
> first uppercase letter and the remaining lowercase letters for my
> query i.e. Smith , HENDERSON etc.


You can do this (example runs in Northwind):

SELECT *
FROM Customers
WHERE CompanyName COLLATE Latin1_General_BIN LIKE '[A-ZÀ-Ý]%'
AND CompanyName COLLATE Latin1_General_BIN NOT LIKE '_%[A-ZÀ-Ý]%'

The requirements is somewhat relaxed here. You will actually get
hits for "J1234" or "D....". Depending on your data, this may or
may not help.

Please note that it is not likely that SQL Server will use an index
for this search.

--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 08:06 PM
Steve
 
Posts: n/a
Default Re: Sort Order and case sensitivity

Thanks for the tip, I have had a problem in trying to using it in
SQL2000 as I get an error regarding the COLLATE function. My database
in case insensitive and accent insensitive, I'm wondering if this may
have something to do with it.

Regards

Steve

Erland Sommarskog <sommar@algonet.se> wrote in message news:<Xns944858DFC6C2Yazorman@127.0.0.1>...
> Steve (murras68@hotmail.com) writes:
> > I have a query which filters records containing uppercase and
> > Lowercase i.e.
> >
> > Smith and SMITH, Henderson and HENDERSON etc.
> >
> > Is there a way that I can filter only those records that contain the
> > first uppercase letter and the remaining lowercase letters for my
> > query i.e. Smith , HENDERSON etc.

>
> You can do this (example runs in Northwind):
>
> SELECT *
> FROM Customers
> WHERE CompanyName COLLATE Latin1_General_BIN LIKE '[A-ZÀ-Ý]%'
> AND CompanyName COLLATE Latin1_General_BIN NOT LIKE '_%[A-ZÀ-Ý]%'
>
> The requirements is somewhat relaxed here. You will actually get
> hits for "J1234" or "D....". Depending on your data, this may or
> may not help.
>
> Please note that it is not likely that SQL Server will use an index
> for this search.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 08:07 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Sort Order and case sensitivity

Steve (murras68@hotmail.com) writes:
> Thanks for the tip, I have had a problem in trying to using it in
> SQL2000 as I get an error regarding the COLLATE function. My database
> in case insensitive and accent insensitive, I'm wondering if this may
> have something to do with it.


Rather than saying that you get an error, it would be somewhat easier
for me to say what is the problem, if you also included the error message.
Of course, also the exact statement you are using would be helpful.

--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 08:07 PM
Steve
 
Posts: n/a
Default Re: Sort Order and case sensitivity

Hi

Here is the error I recieve when trying to run the code in SQL


[Microsoft][ODBC SQL Sever Driver][SQL Server]Line 1 : Incorrect
syntax near 'COLLATE'

Regards

Steve

Erland Sommarskog <sommar@algonet.se> wrote in message news:<Xns944A95DF6AD7CYazorman@127.0.0.1>...
> Steve (murras68@hotmail.com) writes:
> > Thanks for the tip, I have had a problem in trying to using it in
> > SQL2000 as I get an error regarding the COLLATE function. My database
> > in case insensitive and accent insensitive, I'm wondering if this may
> > have something to do with it.

>
> Rather than saying that you get an error, it would be somewhat easier
> for me to say what is the problem, if you also included the error message.
> Of course, also the exact statement you are using would be helpful.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 08:07 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Sort Order and case sensitivity

Steve (murras68@hotmail.com) writes:
> Here is the error I recieve when trying to run the code in SQL
>
>
> [Microsoft][ODBC SQL Sever Driver][SQL Server]Line 1 : Incorrect
> syntax near 'COLLATE'


Since you did not provide the statment, I will have to guess. Assuming
that you used the statement that I gave as example, my guess is that
your database is not at compability level 80. COLLATE was added to
SQL 2000, so if your database is set at backward compatinility, COLLATE
is not available.

You can use sp_dbcmplevel to both determine the compatibility level and to
change it.

--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 08:07 PM
Steve
 
Posts: n/a
Default Re: Sort Order and case sensitivity

Hi,

The compability level was 70.

Thanks

Steve

Erland Sommarskog <sommar@algonet.se> wrote in message news:<Xns944B83AD61726Yazorman@127.0.0.1>...
> Steve (murras68@hotmail.com) writes:
> > Here is the error I recieve when trying to run the code in SQL
> >
> >
> > [Microsoft][ODBC SQL Sever Driver][SQL Server]Line 1 : Incorrect
> > syntax near 'COLLATE'

>
> Since you did not provide the statment, I will have to guess. Assuming
> that you used the statement that I gave as example, my guess is that
> your database is not at compability level 80. COLLATE was added to
> SQL 2000, so if your database is set at backward compatinility, COLLATE
> is not available.
>
> You can use sp_dbcmplevel to both determine the compatibility level and to
> change it.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:21 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com