In my stored procedure I INSERT a record into table 1. Column C is defined as UNIQUEIDENTIFIER with default set as (newid()). I now want to use the new Column C value and INSERT 20 new records into table 2 with table 2 column A being table 1 column C value and table 2 column B be the values 1-20. My question is: in my stored procedure, how do I access the new UNIQUEIDENTIFIER value generated on the table 1 INSERT?
Table 1
A varchar(4)
B varchar(4)
C uniqueidentifier DEFAULT (newid)())
Table 2
A uniqueidentifier
B int
Table1 Column C should now exist with a UNIQUEIDENTIFIER value
EXAMPLE DATA
Table 1
HELLO WORLD {F4074B47-78FB-447F-A5BA-0C1348EFDAF4}
Table 2
{F4074B47-78FB-447F-A5BA-0C1348EFDAF4} 1
{F4074B47-78FB-447F-A5BA-0C1348EFDAF4} 2
{F4074B47-78FB-447F-A5BA-0C1348EFDAF4} 3
.
.
.
{F4074B47-78FB-447F-A5BA-0C1348EFDAF4} 20
Table 1
A varchar(4)
B varchar(4)
C uniqueidentifier DEFAULT (newid)())
Table 2
A uniqueidentifier
B int
Code:
create procedure dbo.spADDTable1
(@a varchar(4),
@b varchar(4)) as
BEGIN TRANSACTION
INSERT into table1(A,B) VALUES(@a,@b)
COMMIT
Table1 Column C should now exist with a UNIQUEIDENTIFIER value
EXAMPLE DATA
Table 1
HELLO WORLD {F4074B47-78FB-447F-A5BA-0C1348EFDAF4}
Table 2
{F4074B47-78FB-447F-A5BA-0C1348EFDAF4} 1
{F4074B47-78FB-447F-A5BA-0C1348EFDAF4} 2
{F4074B47-78FB-447F-A5BA-0C1348EFDAF4} 3
.
.
.
{F4074B47-78FB-447F-A5BA-0C1348EFDAF4} 20