BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

MSSQL 2000 and LIKE operator not behaving like in MSSQL 6.5

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Tomislav Kardaš
Guest





PostPosted: Wed Aug 18, 2004 10:42 am    Post subject: MSSQL 2000 and LIKE operator not behaving like in MSSQL 6.5 Reply with quote



Hi!

Today I discovered strange thing. I have a database that is upraded
from MSSQL 6.5. There is a table Clients that has a field Name
varchar(30). There is a record in that table with value 'BANK'. If I
issue a select:

select Name
from Clients
where Name like 'BANK%'

it does not return any rows. But if I change to like 'BANK' or even
like 'BAN%K%' than it returns the expected row.

In SQL server 6.5 this was not the behaviour. This select should
return this row. Now I have to rewrite all procedures that use this
kind of matching to somethink wich work as is:

select Name
from Clients
where Name+' ' like 'BANK%'

I have tried to reproduce this behaviour by creating a new table but
surprisingly it worked OK. So, there must be some problem with the
upgrade of the old MSSQL 6.5 tables that causes this behaviour.

Can someone comment on this? Is there any easy way to correct the
problem without rewriting the procedures?

tomi.
Back to top
Martyn Ayers
Guest





PostPosted: Wed Aug 18, 2004 11:59 am    Post subject: Re: MSSQL 2000 and LIKE operator not behaving like in MSSQL Reply with quote



Tomi,

Quote:
So, there must be some problem with the
upgrade of the old MSSQL 6.5 tables that causes this behaviour.

I think that must be right. We upgraded from 6.5 to 2000 a couple of
years ago and have never had this problem, although my apps use LIKE
extensively. We used BCP to export and re-import data to move it
across. I've heard of strange results when using other methods to
move the data, like individual columns getting tagged with unexpected
collations.

Would be worth a bit of googling before doing a lot of work, I think.

Cheers, Martyn




Back to top
Mike Shkolnik
Guest





PostPosted: Wed Aug 18, 2004 1:06 pm    Post subject: Re: MSSQL 2000 and LIKE operator not behaving like in MSSQL Reply with quote



Try to analyze (collect statistic) for this table and try again to execute
your query

--
With best regards, Mike Shkolnik
EMail: [email]mshkolnik (AT) scalabium (DOT) com[/email]
http://www.scalabium.com

"Tomislav Karda " <nomail@sorry> wrote

Quote:
Hi!

Today I discovered strange thing. I have a database that is upraded
from MSSQL 6.5. There is a table Clients that has a field Name
varchar(30). There is a record in that table with value 'BANK'. If I
issue a select:

select Name
from Clients
where Name like 'BANK%'

it does not return any rows. But if I change to like 'BANK' or even
like 'BAN%K%' than it returns the expected row.

In SQL server 6.5 this was not the behaviour. This select should
return this row. Now I have to rewrite all procedures that use this
kind of matching to somethink wich work as is:

select Name
from Clients
where Name+' ' like 'BANK%'

I have tried to reproduce this behaviour by creating a new table but
surprisingly it worked OK. So, there must be some problem with the
upgrade of the old MSSQL 6.5 tables that causes this behaviour.

Can someone comment on this? Is there any easy way to correct the
problem without rewriting the procedures?

tomi.



Back to top
Tomislav Kardaš
Guest





PostPosted: Wed Aug 18, 2004 6:44 pm    Post subject: Re: MSSQL 2000 and LIKE operator not behaving like in MSSQL Reply with quote

Hi Mike and Martyn!

I found out that this behaviour is because of index that is existing
on that column. When I remove the index then it works as expected.

Index is created as:

CREATE INDEX [idx_Clients_Name] ON [dbo].[Clients]([Name]) ON
[PRIMARY]
GO

This is very strange because definitely on MSSQL 6.5 it don't behave
that way!

Now I changed my code in stored procedures to:

select ...
from Clients
where name+' ' like @match+'%'

and that works OK when @match equals name, but it's a bug in
MSSQL2000.

If you want to try it yourself do this:

create table tmp (
x varchar(30) not null
)

CREATE INDEX idx_tmp ON tmp(x)

insert into tmp values ('BANK')

select * from tmp
where x like 'BANK%'

drop table tmp
go

If index is created select returns no rows, and if index is not
created (put it in comment) then select returns one row. This
behaviour must definitely be a bug. How can select result depend if
index is created over the column or not?

My SQL server version is:

Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 1)

tomi.
Back to top
Viatcheslav V. Vassiliev
Guest





PostPosted: Thu Aug 19, 2004 6:34 am    Post subject: Re: MSSQL 2000 and LIKE operator not behaving like in MSSQL Reply with quote

Try install SP3 on MS SQL Server. Just tested your proc and it works OK -
one row returned (at least in Query Analyzer).

//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)

"Tomislav Karda " <nomail@sorry> ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:4123a184.307597902 (AT) newsgroups (DOT) borland.com...
Quote:
Hi Mike and Martyn!

I found out that this behaviour is because of index that is existing
on that column. When I remove the index then it works as expected.

Index is created as:

CREATE INDEX [idx_Clients_Name] ON [dbo].[Clients]([Name]) ON
[PRIMARY]
GO

This is very strange because definitely on MSSQL 6.5 it don't behave
that way!

Now I changed my code in stored procedures to:

select ...
from Clients
where name+' ' like @match+'%'

and that works OK when @match equals name, but it's a bug in
MSSQL2000.

If you want to try it yourself do this:

create table tmp (
x varchar(30) not null
)

CREATE INDEX idx_tmp ON tmp(x)

insert into tmp values ('BANK')

select * from tmp
where x like 'BANK%'

drop table tmp
go

If index is created select returns no rows, and if index is not
created (put it in comment) then select returns one row. This
behaviour must definitely be a bug. How can select result depend if
index is created over the column or not?

My SQL server version is:

Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 1)

tomi.



Back to top
Tomislav Kardaš
Guest





PostPosted: Fri Aug 20, 2004 5:04 am    Post subject: Re: MSSQL 2000 and LIKE operator not behaving like in MSSQL Reply with quote

Hi Viatcheslav!

On Thu, 19 Aug 2004 10:34:29 +0400, "Viatcheslav V. Vassiliev"
<support (AT) oledbdirect (DOT) com> wrote:

Quote:
Try install SP3 on MS SQL Server. Just tested your proc and it works OK -
one row returned (at least in Query Analyzer).

I'll look for it.

tomi.

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.