July 24, 2007 at 9:44 am
This is really wierd and I hope someone can shed some light -
Why does doing this pattern search hit on the lower case 'a'?
SELECT PATINDEX ('%[¾-À]%', 'abcdefghijk')
Same this as doing:
declare @Pattern varchar(250)
set @Pattern = '%['+char(190)+'-'+char(192)+']%'
SELECT PATINDEX (@Pattern, 'abcdefghijk')
Now if I look for these characters individually, it does not find anything..Is this an MS bug?
Any help is appreaciated, thanks..
July 24, 2007 at 11:13 am
This may actually an easy one. You are not looking for two characters. You are looking for a range of characters. I'll bet if you check, the lower case a falls between the 3/4 and A with the tilde.
-SQLBill
July 24, 2007 at 11:20 am
Actually no, the ascii char code for lower case "a" is 97. The range I was looking in was from 190 - 192.
July 24, 2007 at 1:21 pm
Here is my guess, you have a case insensitive collation, therefore 'a' = 'A'. I ran you select on my system and it returns a 0, and I use a case sensitive collation.
July 24, 2007 at 1:24 pm
Possibly also Accent Insensitive on your collation.
July 24, 2007 at 1:26 pm
Case insensitive collation, ran it on one of our servers with a case insensitve collation and it hit on the 'a'.
July 24, 2007 at 3:19 pm
After pulling some hairs I found that char(192)À is actually made up of char(97) a and char(145) ‘ so when I do a "like" search it hits on a, because technically it's made up of that character. Computers..eh'
July 24, 2007 at 3:48 pm
I don't think that has anything to do with it. What is the collation of your server? I think you will find it is set to a case insensitive collation.
July 24, 2007 at 5:27 pm
Nope... not a PATINDEX bug... and you don't need to mess with the server default settings (case sensitive servers are a huge pain!).
This will do it for you...
SELECT PATINDEX ('%[¾-À]%', 'bcdeafg' COLLATE Latin1_General_BIN )
The "Latin1_General_BIN" collation requires a match at the BINary level...
--Jeff Moden
Change is inevitable... Change for the better is not.
July 24, 2007 at 6:18 pm
Jeff, I wasn't suggesting that server collation be changed, just that it be checked. We have several PeopleSoft servers and they are set to Latin1_General_BIN, so when I started looking at our Data Warehouse, I choose Later_General_BIN2 for the collation there. Plus, although our other systems (SIS) are case insensitive, all the data is mixed case. We went the case sensitive.
July 24, 2007 at 7:47 pm
Shoot, Lynn... I knew that... you knew that... I just wanted to make sure Kung Lao knew that. Whether anyone suggests changing the server collation or not, I always post that you don't have to to solve this simple problem because some people just don't know about the COLLATE clause and end up going off the deep end at the server level.
Kung Lao... are you all set, now?
--Jeff Moden
Change is inevitable... Change for the better is not.
July 24, 2007 at 9:05 pm
Jeff, Just making sure, some could take it that I was. I didn't test throwing in the collate in the select on the case insensitive server to see if that would help, but I could tomorrow if asked.
l8r Jeff!
July 25, 2007 at 3:22 pm
Jeff that does it, you tha man - thanks!
July 25, 2007 at 6:23 pm
Thanks for the feedback, Kung Lao.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 30, 2007 at 6:57 am
Jeff, you're right on. Thanks!
Viewing 15 posts - 1 through 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply