Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 MERGE and OUTPUT

Author  Topic 

ldygahan
Starting Member

3 Posts

Posted - 2010-07-30 : 12:01:11
I'd like to finish off my MERGE query by adding full history table outputs. So far I have successfully written OUTPUT and the query is inserting INSERT, and UPDATE actions (the rest of the data written as well) and then I get DELETE action rows but they do not contain the deleted columns. They are null. I understand that my output part of query has the inserted.columns and not deleted.columns...
I'm rather new in this... my main questions is, Can I use two OUTPUTs in MERGE? So far SQL complains a lot when I try to add another OUTPUT for deletes...
I'll appreciate any suggestions.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-07-30 : 15:02:38
MERGE ...
USING ... ON ...
WHEN MATCHED THEN UPDATE ...
WHEN NOT MATCHED BY TARGET THEN INSERT ...
WHEN NOT MATCHED BY SOURCE THEN DELETE ...
OUTPUT $action, ...

Then you can use the statement as Composable Dml. See more here
http://weblogs.sqlteam.com/peterl/archive/2009/04/08/Composable-DML.aspx



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

ldygahan
Starting Member

3 Posts

Posted - 2010-07-31 : 09:13:03
Thanks, but this is the part that worked fine I had a problem with the output part but I think I got it now.
output inserted.newvalue, deleted.oldvalue, $action, date_modified

I think I'm good now. Thanks.
Go to Top of Page
   

- Advertisement -