Hi,
I'm writing a stored procedure to
(1) Create a new record in one table (A) and store its identity value;
(2) then create a new record in a second table (B) and store *its* identity value;
(3) then create a new record in a third table (C) and populate it using the identity values generated in the first two steps.
I've included the basic code below.
Every time I run the procedure, a new record is created an populated in Table A; but I then get the following error message:
Server: Msg 208, Level 16, State 3, Procedure spInsertItem, Line 36 Invalid object name 'TableB'.
Can anyone tell me why this is happening?
I'm writing a stored procedure to
(1) Create a new record in one table (A) and store its identity value;
(2) then create a new record in a second table (B) and store *its* identity value;
(3) then create a new record in a third table (C) and populate it using the identity values generated in the first two steps.
I've included the basic code below.
Every time I run the procedure, a new record is created an populated in Table A; but I then get the following error message:
Server: Msg 208, Level 16, State 3, Procedure spInsertItem, Line 36 Invalid object name 'TableB'.
Can anyone tell me why this is happening?
Code:
USE Database
GO
CREATE PROC spInsertItem
@VariableA1,
@VariableA2,
@VariableB1,
@VariableB2
AS
/* Create and populate new record in TableA*/
INSERT INTO TableA
VALUES
(
@VariableA1,
@VariableA2
)
/* Move the identity value of the new TableA record into a variable */
DECLARE @IdentityA int
SET @IdentityA = @@IDENTITY
/* Create and populate new record in TableB*/
INSERT INTO B
VALUES
(
@VariableB1,
@VariableB2
)
/* Move the identity value of the new TableB record into a variable */
DECLARE @IdentityB int
SET @IdentityB = @@IDENTITY
/* Create and populate new TableC record */
INSERT INTO TableC
VALUES
(
(@IdentityA,
@IdentityB
)
GO