I want to take the value from an autonumbered field, and put that value into another table.
Example:
CREATE PROCEDURE add_customer
@FirstName varchar(50),
@LastName varchar(60),
@CompanyName varchar(100),
@EMail varchar(100),
@Address varchar(100),
@City varchar(100),
@State varchar(100),
@PostalCode varchar(20),
@Country varchar(50),
@CustomerID int OUTPUT
AS
BEGIN TRAN Add_Customer1
INSERT INTO Customer
(FirstName, LastName,EMail)
VALUES
(@FirstName, @LastName, @EMail)
SELECT @CustomerID = CustomerID FROM Customer
COMMIT TRAN Add_Customer1
GO
BEGIN TRAN Add_Customer2
INSERT INTO Customer_extra
(CustomerID, CompanyName, Address, City, State, PostalCode, Country)
VALUES
(@CustomerID, @CompanyName, @Address, @City, @State, @PostalCode, @Country)
EXEC add_customer
COMMIT TRAN Add_Customer2
GO
I get an error that I must declare the variable "CustomerID". If I omit The "GO" in the "BEGIN TRAN Add_Customer1", everything seems OK in SQL. But still I receive an error on the webpage that request the procedure. Someone that can help me with this?