SUMMARY:
I need to use the OUTPUT clause on INSERT to return columns that do not exist in the table I am inserting into. If I can avoid this, I do not want to add columns to the table I am inserting into.
DETAILS:
There is only one column in my FinishedDocument table. This is the table I'm pasting.
FinishedDocument
- DocumentID
The My Document table has two columns. This is the table from which I need to return data.
Document - DocumentID
- Description
Next insert one line in FinishedDocument. His OUTPUT clause returns the DocumentID that was inserted. This works, but it does not give me a description of the inserted document.
INSERT INTO FinishedDocument
OUTPUT INSERTED.DocumentID
SELECT DocumentID
FROM Document
WHERE DocumentID = @DocumentID
I need to return from the table Document and DocumentID and the description of the corresponding document from INSERT.
What syntax do I need to remove? I think this is possible with only one INSERT statement, by setting the OUTPUT clause (somehow I don't understand)?
Is there a smarter way that doesn't look like the path I'm going to here?
EDIT: SQL Server 2005
lance source
share