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 2005 Forums
 Transact-SQL (2005)
 copying column data from one table to another

Author  Topic 

darenkov
Yak Posting Veteran

90 Posts

Posted - 2007-06-16 : 12:02:08
i am trying to copy some columns from 'Table A' to 'Table B '(which is easy enough), but I am also trying to insert an additional value into 'Table B' which comes from a parameter (not a value from 'Table A'). I am not sure how to make it work. my code is below:

CREATE PROCEDURE [dbo].[prc_CreateOrder]

@CustomerID int,
@CartID varchar(50)

AS

BEGIN

DECLARE @OrderID int

SET NOCOUNT ON;


INSERT INTO [dbo].[Orders]
(CustomerID)
VALUES
(@CustomerID)

SET @OrderID = SCOPE_IDENTITY()

INSERT INTO [dbo].[OrderDetails]
(OrderID,
ProductID,
SalePrice,
Quantity)

(@OrderID, <--I want to insert this
SELECT ProductID,
Price,
Quantity
FROM [dbo].[ShoppingCart])

WHERE CartID = @CartID

END









jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-06-16 : 12:05:19
INSERT INTO [dbo].[OrderDetails] (OrderID,ProductID,SalePrice,Quantity)
SELECT @OrderID,ProductID,Price,Quantity
FROM [dbo].[ShoppingCart]
WHERE CartID = @CartID


elsasoft.org
Go to Top of Page

darenkov
Yak Posting Veteran

90 Posts

Posted - 2007-06-16 : 12:23:17
thanks muchly
Go to Top of Page
   

- Advertisement -