SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 LIKE operator problem (or is it just me?)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jansen
Starting Member

Denmark
5 Posts

Posted - 09/16/2002 :  05:11:47  Show Profile  Visit jansen's Homepage  Reply with Quote
Hello all!

I have a problem with the result of the like operator!

Try out ...:

create table tblName
(
vchrName varchar(10) null
)

insert into tblName (vchrName) values ('ab')
insert into tblName (vchrName) values ('aab')
insert into tblName (vchrName) values ('aaab')

select * from tblName where vchrName like 'a%'
select * from tblName where vchrName like 'aa%'

The first select I would expect all rows but it only gives me [ab]??

Best regards
Jansen

Andraax
Aged Yak Warrior

Sweden
790 Posts

Posted - 09/16/2002 :  06:31:43  Show Profile  Reply with Quote
I get the expected results... All three rows when using 'a%'. Strange!?

Go to Top of Page

jansen
Starting Member

Denmark
5 Posts

Posted - 09/16/2002 :  09:44:34  Show Profile  Visit jansen's Homepage  Reply with Quote
Hello Andraax

I think we are looking at a possible bug report....
My coallation on the vchrName column is: Danish_Norwegian, dictonary sort, Accent Sensitive.

When I change it, it also works?!? - What collation is your vchrName column??

By the way...I'm running SQL2K with SP2

/Jansen

Go to Top of Page

Andraax
Aged Yak Warrior

Sweden
790 Posts

Posted - 09/19/2002 :  06:56:09  Show Profile  Reply with Quote
Mine is Swedish_Finnish, dictionary, accent sensitive.

Go to Top of Page

rrb
SQLTeam Poet Laureate

Australia
1478 Posts

Posted - 12/02/2002 :  00:55:11  Show Profile  Reply with Quote
Use the binary sort collation: (case sensitive - hence - lower)

select * from tblName where lower(vchrName) collate Danish_Norwegian_BIN
like 'a%'
select * from tblName where lower(vchrName) collate Danish_Norwegian_BIN
like 'aa%'


from BOL:
quote:
Sorts and compares data in Microsoft® SQL Server™ tables based on the bit patterns defined for each character. Binary sort order is case-sensitive, that is lowercase precedes uppercase, and accent-sensitive. This is the fastest sorting order.
If this option is not selected, SQL Server follows sorting and comparison rules as defined in dictionaries for the associated language or alphabet.



Cheers

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"

Edited by - rrb on 12/02/2002 00:59:16
Go to Top of Page

Arnold Fribble
Yak-finder General

United Kingdom
1961 Posts

Posted - 12/02/2002 :  07:42:37  Show Profile  Reply with Quote
It's because the Danish_Norwegian collation is (still) considering aa to be a separate letter from a. Of course, this is ambiguous so it doesn't work properly. The strange thing is that aa <> å unless the comparison is accent-insensitive.


SELECT 1
WHERE
'aa' COLLATE Danish_Norwegian_CI_AS =
'å' COLLATE Danish_Norwegian_CI_AS
-- returns nothing

SELECT 1
WHERE
'aa' COLLATE Danish_Norwegian_CI_AI =
'å' COLLATE Danish_Norwegian_CI_AI
-- returns 1

SELECT 1
WHERE
'aa' COLLATE Danish_Norwegian_CI_AI =
'á' COLLATE Danish_Norwegian_CI_AI
-- returns nothing

SELECT 1
WHERE
'å' COLLATE Danish_Norwegian_CI_AI =
'á' COLLATE Danish_Norwegian_CI_AI
-- returns nothing





Edited by - Arnold Fribble on 12/02/2002 07:43:06
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000