Calling stored procedure from another stored procedure SQL Server

后端 未结 3 603
予麋鹿
予麋鹿 2020-12-14 00:32

I have 3 insert stored procedures each SP inserts data in 2 different tables

Table 1          Table 2                
idPerson         idProduct                      


        
3条回答
  •  既然无缘
    2020-12-14 00:59

    You could add an OUTPUT parameter to test2, and set it to the new id straight after the INSERT using:

    SELECT @NewIdOutputParam = SCOPE_IDENTITY()
    

    Then in test1, retrieve it like so:

    DECLARE @NewId INTEGER
    EXECUTE test2 @NewId OUTPUT
    -- Now use @NewId as needed
    

提交回复
热议问题