Hello, SQL 2008R2
I was looking at the MERGE command with respect to a process I am currently using. I thought the INSERT/UPDATE done by MERGE would speed things up.
Problem: Currently during the update a field is updated in target that indicates date of change for one column. Can this be done with a merge?
Note that the current process works so I do not need to change it but would like to know if it is possible to do the update within the MERGE or do I need to use OUTPUT and do a second update.
Thank you,
djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
I was looking at the MERGE command with respect to a process I am currently using. I thought the INSERT/UPDATE done by MERGE would speed things up.
Problem: Currently during the update a field is updated in target that indicates date of change for one column. Can this be done with a merge?
Code:
UPDATE target
SET ....
-- various columns updated then
, myColumn = #Changes.myColumn
, myColumnChanged =
CASE
-- old value not equal to new value or no old value but have a new value
WHEN target.myColumn <> #Changes.myColumn OR
(target.myColumn IS NULL AND #Changes.myColumn IS NOT NULL)
THEN CAST(GETDATE() AS DATE)
ELSE myColumnChanged
END
FROM target
INNER JOIN #Changes
ON target.PKvalue = #Changes.PKvalue
Note that the current process works so I do not need to change it but would like to know if it is possible to do the update within the MERGE or do I need to use OUTPUT and do a second update.
Thank you,
djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!