I have 6 tables, 3 temp tables (TEMP1, TEMP2, TEMP3) and 3 tables holding actual data (ACTUAL1, ACTUAL2, ACTUAL3) that needs to be updated from the data in the corresponding TEMP table.
I have a stored procedure that accepts an ITEM_ID which relates to each of the TEMP tables. (Each TEMP table has a field for ITEM_ID). The 3 ACTUAL tables do not have this similar ID. ACTUAL1 has a field for ITEM_ID, but ACTUAL2 has an ACTUAL1_ID, and ACTUAL3 had an ACTUAL2_ID.
So the ACTUAL tables are decendendants of each the lower ACTUAL tables. (I hope this all makes sense.)
I can update the first table like this:
CREATE PROCEDURE sp_whatever @ITEM_ID int AS
UPDATE ACTUAL1
SET field1 = t1.field1
field2 = t1.field2
etc...
FROM TEMP1 t1
WHERE ACTUAL1.item_id = t1.item_id
AND t1.@ITEM_ID
My problem is I need to then do the same type of thing for ACTUAL2 and ACTUAL3 but WHERE ACTUAL2.actual1_id = somehow get each ACTUAL1 ID, and the same for ACTUAL3 but with ACTUAL2's ID field...
If this makes sense, any help would be much appreciated... if not, oh well. Thanks for reading anyway.
I have a stored procedure that accepts an ITEM_ID which relates to each of the TEMP tables. (Each TEMP table has a field for ITEM_ID). The 3 ACTUAL tables do not have this similar ID. ACTUAL1 has a field for ITEM_ID, but ACTUAL2 has an ACTUAL1_ID, and ACTUAL3 had an ACTUAL2_ID.
So the ACTUAL tables are decendendants of each the lower ACTUAL tables. (I hope this all makes sense.)
I can update the first table like this:
CREATE PROCEDURE sp_whatever @ITEM_ID int AS
UPDATE ACTUAL1
SET field1 = t1.field1
field2 = t1.field2
etc...
FROM TEMP1 t1
WHERE ACTUAL1.item_id = t1.item_id
AND t1.@ITEM_ID
My problem is I need to then do the same type of thing for ACTUAL2 and ACTUAL3 but WHERE ACTUAL2.actual1_id = somehow get each ACTUAL1 ID, and the same for ACTUAL3 but with ACTUAL2's ID field...
If this makes sense, any help would be much appreciated... if not, oh well. Thanks for reading anyway.