Click here to Skip to main content
16,018,347 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i Have 2 Table named Purchase Master And Purchase detail
and insert record using stored procedure

First i create Store Procedure named Ins_PurchaseMaster (@Parameter....) and Write insert code ...

and after i create Ins_PurchaseDetail (@Parameter....) and Write to code ...

and problem is how to get new Purchase Master Id in Ins_PurchaseDetail SP..... Using Scope_Identity Or @@Identity
Posted
Comments
_Asif_ 8-Sep-14 4:16am    
Well can't you return identity from Ins_PurchaseMaster SP and pass it to Ins_PurchaseDetil SP?

1 solution

I would have an OUT parameter to the SP which returns the ID value just created to whatever it was called from. That way, you can pass it through to the next SP.
But...I wouldn't do that in two SP's - I'd want to do it in a single SP with a Transaction - so that if the second INSERT fails, I can roll back the first as well and leave the DB in a "stable" state.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900