0

In my stored procedure I need to insert a record in a particulat table using corresponded stored procedure. This procedure returns as a result a hell of fields, but what I need from the stored procedure is only content of columnd [Id].

So If there is a way to extract this information from stored procedure without a need of creating a temporary table or table variable that duplicates all the expected hell of fields and inserting the procedure result in it? Here I mean the folowing:

DECLARE @Reciever Table (field1 INT, Field2 varchar(255), ..., fieldn DateTime, ... fieldX float)
INSERT INTO @Reciever
EXEC ProcThatInserts @param1, @param2

How can I do the same without replicating structure of the stored procedure output into my table variable? Thanks!

P.S. The "ProcThatInserts" makes several insertions in different tables. Some of the inserts activete insert triggers which can make their own inserts

Yaugen Vlasau
  • 2,148
  • 1
  • 17
  • 38

1 Answers1

0

I think it sounds like you need to return the identity of the inserted row, in which case you should be able to specify the output to be the identiy field. Here is a SO post with more details on how to do it... SQL Server - Return value after INSERT

Community
  • 1
  • 1
Steph Locke
  • 5,951
  • 4
  • 39
  • 77
  • the insertion procedure does inserts in several tables and the "target" table insertion is not the last insruction in the stored procedure. How I can detect the identity related to my target table? – Yaugen Vlasau Jun 11 '13 at 10:46
  • I think if you use the output clause on only the insert you're interested in it should output just that one – Steph Locke Jun 11 '13 at 13:40