How are you inserting your data? If you're doing stored procedures, or even direct SQL, then you get the last ID using scope_identity()
set nocount on; insert into table values (...); select SCOPE_IDENTITY() as NewID
You can execute that and treat it like something that returns a single result (execuescalar if you are using ado.net) and it returns the id of the last-inserted table. You can use that in your next insert.
I'm afraid I no longer use this forum due to the new point allocation system.
All-Star
37441 Points
9076 Posts
Re: How do i INSERT the new record ID from table#1 into table#2 in the same process?
Aug 24, 2013 12:27 PM|AidyF|LINK
How are you inserting your data? If you're doing stored procedures, or even direct SQL, then you get the last ID using scope_identity()
set nocount on; insert into table values (...); select SCOPE_IDENTITY() as NewID
You can execute that and treat it like something that returns a single result (execuescalar if you are using ado.net) and it returns the id of the last-inserted table. You can use that in your next insert.