John.Hagen (9/6/2013)
Ok, adding the deleted in front of that column makes it work. I am getting the records into the tables as needed. It is also entering 10 rows of 'NULL' in every column along with the 7 rows of deleted.10 rows happens to be the number of records that the merge statement inserts . I tried to get some data for the inserted records by adding to the statement. I received 'Column name or number of supplied values does not match table definition.'
Delete
OUTPUT
DELETED.OID,
DELETED.Version,
DELETED.QK,
DELETED.GD,
DELETED.Geometry
INSERTED.OID,
INSERTED.Version,
INSERTED.QK,
INSERTED.GD,
INSERTED.Geometry
GETDATE()
into table1
It would not hurt to have the inserted values added to the tables.
That definitely won't work because when you use output it is like creating an insert statement. That means the columns in the output need to match the table that you are inserting into. You could add columns for both inserted and deleted values. If you do that I would consider adding one more column for Action. You can reference that by $Action in the output. That would tell you if it was an insert or a delete.
You should probably spend some time digging through the details of the MERGE statement. http://technet.microsoft.com/en-us/library/bb510625.aspx
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/