Hi i have the following code which i would like to loop
This is the list i would like to select from
Select Distinct Serial from dbo.VwDatesReceivedVsDatesDispatched
serial should be = @Serial
Second select
Select top 1 Min(Workcompleted) dispatcheddate,min (dateReceived)Receiveddate,Serial,RID,did,dispatchorderid from VwDatesReceivedVsDatesDispatched where Manufacturerserialnumber = '" & @serial & "' and dispatchorderid is null group by Seril,RID,did,dispatchorderid
RID should be = @rid
DID should be = @Did
to get the date Received vs DateDispatched by serial number
first check
Select * from Receiving where id =@rid
if this has rows then
Update Receiving set dispatchorderid=@did where id =@rid
Else
Select * from ReceivingArchive where id =@rid
if has rows then
Update ReceivingArchive set dispatchorderid=@did where id =@rid
loop
[EDIT]
What i need to do is to create a stored procedure which will update my Receiving table column Dispatchorderid, so that my Received date can be linked to a dispatched date,
the first query on the page shows all serials without any dispatched order id.
the second query returns the min date received and the min date dispatched as well as the Received id and dispatched id for those dates
E.G.
id | Serial |ReceievedDate | id | DispatchedDate
80 |98654 |2013-04-01 |5441| 2013-04-06
The Select * from Receiving table will look as follows before the update
id|Serial|DateReceived|Dispatchid
80|98654 |2013-04-01 |NULL
Then i need to update Receiving table to show the following
id|Serial|DateReceived|Dispatchid
80|98654 |2013-04-01 |5441
[/EDIT]