I have a basic stored procedure that adds a new record to a table with a structure like the following. The table also has a column "itemID" that is set to auto-incrementing to create a unique id for each record.
I would like to use Output to get this id from the new record I inserted and then use this to add a new record to another table (Table2 with columns colD, colE, colF). colF in Table2 should be the Output from the below as this is the id that links both tables.
Can someone here tell me how this would work as I am pretty new to SQL and have never done this before ?
My stored procedure (example):
ALTER PROCEDURE [dbo].[CreateStuff]
@colA datetime,
@colB varchar(50),
@colC nvarchar(20)
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO Table1
(
colA,
colB,
colC
)
SELECT @colA,
@colB,
@colC
END
Many thanks for any help with this, Tim.