in regards to the thread about implementing oracle cursors in sql server thread183-538939 im posting that what follows as a new thread:
anyway, what i would like to achieve is an "update-insert" process.
taking hint from SQLSister, take an example wherein we have the following code:
as one would note the above "UPDATE" would AFFECT all the rows in the destination table. fairly ok if we are dealing with few records, but what IF there are so many records in the table.
is there a possible way of only updating the records that has actually changed?
using some sort of an "archived" flag on the source table wouldn't work because that particular table is located on a system that i have "no-touch" privileges.
anyway, what i would like to achieve is an "update-insert" process.
taking hint from SQLSister, take an example wherein we have the following code:
Code:
CREATE PROCEDURE prc_TestUpdateInsert
AS
-- update process first
UPDATE T_Destination_Table
SET
Product_Name = Src.Record_Name,
Product_Value = Src.Record_Value
FROM
T_Source_Table AS Src
WHERE
Src.Record_ID = T_Destination_Table.Product_Code
-- insert process second
INSERT INTO T_Destination_Table (
Product_Code,
Product_Name,
Product_Value
)
SELECT
Src.Record_ID, -- Record_ID maps to Product_Code
Src.Record_Name,
Src.Record_Value
FROM
T_Source_Table AS Src LEFT JOIN T_Destination_Table
ON Src.Record_ID = T_Destination_Table.Product_Code
WHERE
T_Destination_Table.Product_ID IS NULL
GO
as one would note the above "UPDATE" would AFFECT all the rows in the destination table. fairly ok if we are dealing with few records, but what IF there are so many records in the table.
is there a possible way of only updating the records that has actually changed?
using some sort of an "archived" flag on the source table wouldn't work because that particular table is located on a system that i have "no-touch" privileges.