April 27, 2007 at 7:44 pm
I am trying to create a query to look for any expression that contains a lowercase character in the description.
SELECT * FROM Table1 WHERE Description LIKE '%[a-z]'
This is still returning all rows that do not contain any lowercase characters.
Outside of creating a CLR or additional functions, does anyone have any idea why this wouldn't be working?
Thanks
April 27, 2007 at 8:39 pm
That requires a change in "COLLATION"... unfortunately, there's a bug in SQL Server that destroys the ability to use collation where a range of letters is included in a LIKE... soooo... the following will NOT work...
SELECT * FROM Table1 WHERE Description LIKE '%[a-z]' COLLATE SQL_Latin1_General_CP850_CS_AS
... but this will... (it's just a bit slower)....
DECLARE @Find VARCHAR(10)
SET @Find = '%[abcdefghijklmnopqrstuvwxyz]' COLLATE SQL_Latin1_General_CP850_CS_AS
SELECT * FROM Table1 WHERE Description LIKE @Find
--Jeff Moden
Change is inevitable... Change for the better is not.
April 28, 2007 at 5:33 pm
Thank you for the response, but I am still getting the same results. What I need to do is to pull only those Descriptions that contain a lower case character, I am still pulling records that are all caps.
What we are trying to do is to locate those records that have a description that was possibly modified outside of our legacy system. Since our legacy system sends us our records in CAPS we need to locate those that contain the lower case characters. I know this is not a 100% solution to locating those records that were modified, but it gives us something to go back to the business with as far as data integrity is concerned.
Thanks again for the response....
April 28, 2007 at 6:14 pm
You mean the second example I posted didn't work? (The first example was how NOT to do it)...
--Jeff Moden
Change is inevitable... Change for the better is not.
April 29, 2007 at 7:12 am
Correct, I tried it out and it returned the same results I was getting before. I copied and pasted your suggestion.
Thank you for your assistance....
April 29, 2007 at 9:06 am
maybe try ...
SELECT * FROM Table1
WHERE Description COLLATE SQL_Latin1_General_CP850_CS_AS
LIKE '%[a-z]' COLLATE SQL_Latin1_General_CP850_CS_AS
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
April 29, 2007 at 11:14 am
I am still receiving the same results, it is still returning rows that do not contain any lower case characters.
Thanks for the assiatance.....
April 29, 2007 at 3:51 pm
Crud... I can't make COLLATION work anyway shape or form with LIKE (thought I did but was wrong)... it only works with an equates...
This one works though... guaranteed...
SELECT *
FROM Bigtest
WHERE CAST(SomeValue AS VARBINARY(8000))
<> CAST(UPPER(SomeValue) AS VARBINARY(8000))
--Jeff Moden
Change is inevitable... Change for the better is not.
April 29, 2007 at 4:10 pm
Problem solved... ALZDBA reminded me of the other collation...
Both of these work (did positive testing instead of negative testing this time, my bad)...
DECLARE @FIND VARCHAR(8000)
SET @FIND = '%[abcdefghijklmnopqrstuvwxyz]%' COLLATE SQL_Latin1_General_CP850_CS_AS
SELECT *
FROM Table1
WHERE Description COLLATE SQL_Latin1_General_CP850_CS_AS
LIKE @FIND
SELECT *
FROM Table1
WHERE Description COLLATE SQL_Latin1_General_CP850_CS_AS
LIKE '%[abcdefghijklmnopqrstuvwxyz]%' COLLATE SQL_Latin1_General_CP850_CS_AS
The key is that as you as you use a range like [a-z], the collation on the like just seems to loose its mind in SQL Server 2000... you must explicity mention every character, instead.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 30, 2007 at 6:17 am
It worked like a charm.
Thank you for all your help, I greatly appreciate it.....
Viewing 10 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply