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
 General SQL Server Forums
 New to SQL Server Programming
 Mass Update

Author  Topic 

Kumar_Anil
Yak Posting Veteran

68 Posts

Posted - 2008-05-08 : 13:43:23
This is a run of the mill application that moves orders from one table to another. There are 2 tables, Ordersummary & HstOrders.
Ordersummary has the following columns...
Identifier
FollowupId
OrderNumber
OrderReference
OrderReferenceOrigin
......
......
HstOrders has the following columns...
Identifier
OrderNumber
OrderReference
OrderType
......
......
The above two tables are bound by Identifier. After each month end, Orders are moved from Ordersummary to HstOrders.

Now my task is to update all rows in OrderSummary with the order details as seen in HSTOrders for ordertype = 'CREDIT'. OrderReferenceOrigin(in Ordersummary) should be updated with the value of Orderreference(from hstorders).

I have to update each row at a time & I need to write a cursor for mass updates where ordersummary.identifier = hstorders.identifier.

Can someone please help with in writing this update statement as I never wrote a cursor.




visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-08 : 13:50:08
Why do you want a cursor? Any specific reason why you dont use a set based soln?

Update o
SET o.OrderReferenceOrigin=h.OrderReference
.....other fields
FROM OrderSummary o
INNER JOIN HstOrders h
ON h.OrderNumber=o.OrderNumber
WHERE h.OrderType='CREDIT'
Go to Top of Page
   

- Advertisement -