0

I'm trying to do something like this but it doesn't work.

DECLARE @Output TABLE( OldReferenceValue INT, NewReferenceValue INT )

INSERT INTO FileManagerReferenceMessage (FileManagerFileID, ReferenceMesssage)
OUTPUT Refs.ID, inserted.ID INTO @Output(OldReferenceValue, NewReferenceValue)
SELECT ID, [Data2] AS ReferenceMessage FROM @References AS Refs WHERE ID <= 0

I am sending into s SQL Server stored procedure a table-valued parameter called @References that contains an ID for a record derived from an external system. The ID in the scenario is a negative number. I want to do a bulk insert of these records letting SQL Server IDENTITY set the local ID and correlate the inserted IDs back to the external system IDS.

halfer
  • 19,824
  • 17
  • 99
  • 186
Danny Ellis Jr.
  • 1,674
  • 2
  • 23
  • 38
  • Possible duplicate - http://stackoverflow.com/q/10949730/1048425 – GarethD Dec 02 '16 at 14:08
  • 1
    Actually, that is probably over complicating things, you can just use `inserted.OldReferenceValue` instead of `refs.ID` in your output clause (considering this is where you are inserting refs.ID to anyway, so they are one and the same thing). – GarethD Dec 02 '16 at 14:11
  • Thanks for the info. I did not show it but I also have to do an update, and I wasn't familiar with the merge statement. GarethD's reference worked for me. Thanks again. – Danny Ellis Jr. Dec 05 '16 at 14:59

0 Answers0