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 2000 Forums
 SQL Server Development (2000)
 cursor removal

Author  Topic 

cat_jesus
Aged Yak Warrior

547 Posts

Posted - 2001-07-13 : 16:06:04
I have an SP that is called from within a cursor. The SP uses a single value that is passed(a key value on all associated tables for this process) we'll call this value customer number. In one of the select queries I have a convoluted select statement that uses two joins and the passed customer in the where clause

So basically we have
pass in @customer

Select...
from
table1 tb1
join table2 tb2 on tb2.customer = tb1.customer
join table3 tb3 on tb3.customer = tb2.customer
where tb1.customer = @customer.


Since I can easily create a table with @customer info in it very quickly and put indexes on it, wouldn't it be easier to simply put a left join just after "table1 tb1" like

left join newtable nt on nt.customer=tb1.customer

This is a huge convoluted select statement but on thing is true, all the tables involved should be tied together by customer.

Basically an aggregate record is being create from the multiple field in the multiple tables tied by customer. I didn't wan't to get too mired in details. If I misunderstand the use of left join, feel free to correct me.


Thanks,
Cat


   

- Advertisement -