Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

stored procedure insert question

$
0
0

I created a stored procedure that is inserting values from a user defined type (ppList) via parameter in the order_detail table. Before this, I create an order_id and would like to add this id to the order_detail table with the @productPrices.  I tried to do this in stored procedure below but did not succeed.


CREATE TYPE [dbo].[ppList]ASTABLE([ProductId][int]NULL,[PriceId][int]NULL);
CREATE PROCEDURE [dbo].[sp_create_order]
	(@userId uniqueidentifier,  @productPrices dbo.ppList READONLY)
AS
	BEGIN
	  DECLARE @orderid int


	  INSERT INTO orders (user_id, confirmed) values(@userId,0);

      --Select last inserted PK
	  SELECT @orderId=@@IDENTITY

	   insert into order_detail (order_id, product_id,price_id) values(@orderId)
         select p.ProductId,
         p.PriceId
         from @productPrices p;



END
RETURN 0



Viewing all articles
Browse latest Browse all 7129

Trending Articles