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