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)
 update or insert

Author  Topic 

yakoo
Constraint Violating Yak Guru

312 Posts

Posted - 2001-11-06 : 13:39:20
I have a situation where I need to either update or insert records from one table into another.

I saw a post from nr that I believe should do the trick
quote:

create table #a (partID int)
insert #a select PartID from products where bikeId = @bikeID

begin tran
update shopping_cartItems
set partQty = partQty + 1
from #a
where #a.partId = shopping_cartItems.partId
and shopping_cartItems.cartId = @cartId

delete #a
from shopping_cartItems
where #a.partId = shopping_cartItems.partId
and shopping_cartItems.cartId = @cartId

insert shopping_cartItems
select ...
from #a

commit tran



I was just wondering if anyone knew how fast and efficient this query was. Right now the data I have is small but in the future it will be rather large. Another thing to point out is that this will be executed within a DTS Package on 15 other tables also.

Does anyone else have any suggestions on how to complete this task?

   

- Advertisement -