guest2013-1
guest
- Joined
- Aug 22, 2003
- Messages
- 19,800
- Reaction score
- 13
i have the following:
The above updates a record that has a different status to the original (it updates all fields). However, sometimes a record is saved with a comment, which doesn't necessarily mean that the status changed.
I want to do this, but it doesn't seem to update the differences:
Any ideas why it's not working?
(example I was working from: http://www.mssqltips.com/sqlservert...to-insert-update-and-delete-at-the-same-time/)
Code:
MERGE datawarehouse_table AS TARGET
USING live_table AS SOURCE
ON (TARGET.ID = SOURCE.ID)
WHEN MATCHED
AND TARGET.STATUS <> SOURCE.STATUS
THEN
UPDATE.....
The above updates a record that has a different status to the original (it updates all fields). However, sometimes a record is saved with a comment, which doesn't necessarily mean that the status changed.
I want to do this, but it doesn't seem to update the differences:
Code:
MERGE datawarehouse_table AS TARGET
USING live_table AS SOURCE
ON (TARGET.ID = SOURCE.ID)
WHEN MATCHED
AND TARGET.STATUS <> SOURCE.STATUS OR TARGET.Comment_1 <> SOURCE.Comment_1 OR TARGET.Comment_2 <> SOURCE.Comment_2 OR TARGET.Comment_3 <> SOURCE.Comment_3 OR TARGET.Comment_4 <> SOURCE.Comment_4
THEN
UPDATE.....
Any ideas why it's not working?
(example I was working from: http://www.mssqltips.com/sqlservert...to-insert-update-and-delete-at-the-same-time/)