Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 INSERT INTO using SELECT and a variable

Author  Topic 

ateup
Starting Member

5 Posts

Posted - 2001-10-15 : 09:02:17
I am trying to insert a record into a saved_orders table. Grab the just inserted id from the table using @@IDENTITY. I know how to do this. It is this part I am lost on. I want to insert all the records from the cart table into the saved_cart table and include the just inserted saved_orders id value. The code below is what I am trying to due. I know this isnt right but thought I would list it.

CREATE PROCEDURE sp_INSERT_ORDER_SPECIAL_TEST

@session_id Varchar(50),
@company_name Varchar(50)

AS

DECLARE @Error Int
DECLARE @newID Int

SET NOCOUNT ON

INSERT INTO saved_orders_special
(
company_name
)
VALUES
(
@company_name
)

SELECT @Error = @@ERROR
SET @newID = @@IDENTITY

If @Error = 0

BEGIN
INSERT INTO saved_cart_special @newID, SELECT prod_id, prod_name FROM cart WHERE session_id = @session_id
END

Thanks ahead of time,
George

   

- Advertisement -