Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Help optimizing stored proc with string compare

Author  Topic 

Gethin
Starting Member

1 Post

Posted - 2009-09-02 : 23:13:00
Hi,
I'm looking to optimize the following query using whatever method possible (temp tables, CTEs etc.)

Insert into bookcollection (bookid, collectionid)
select
b.id, bco.id
from
collectionclassification cc,
bookclassification bcl,
bookcollection bco,
book b
where
cc.collectionid = bco.id and
bco.bookid = b.id and
bcl.collectiontypeid = bco.typeid and
/* This line is the bottleneck */
left(bcl.code, len(cc.startvalue)) between cc.cstartvalue and cc.endvalue and
not exists
(select * from bookcollection ibc where
ibc.bookid = b.id and
ibc.collectionid = bco.id)

Thank you,
G
   

- Advertisement -