I would like to use a table valued parameter to create an invoice. It will insert into the invoice header data table the header and then it will insert the invoice detail all with different tables. The problem is that until now I was doing this using 2 separate procedures
1. insert into invoice header
2. insert into invoice detail - this was done with a foreach loop
foreach row in the invoice insert into invoice detail and it was also adjusting the inventory like so:
USE [Trial]
GO
/****** Object: StoredProcedure [dbo].[ARD_Insert] Script Date: 02/25/2014 15:23:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:Debra
-- Create date: January 28, 2013
-- Description:Insert into the ARD table
-- =============================================
ALTER PROCEDURE [dbo].[ARD_Insert]
-- Add the parameters for the stored procedure here
@InvoiceARD int,
@Item int,
@Description nvarchar(50),
@Qty int,
@Price decimal(10,2),
@TempWOID nvarchar(5),
@InventoryQuantityAddSubtract int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
--BEGIN TRAN
INSERT INTO ARD(INVOICE,ITEM,[DESC],QTY,PRICE,TEMPWOID)
VALUES(@InvoiceARD, @Item, @Description, @Qty, @Price, @TempWOID)
DECLARE @Type nvarchar(3)
SET @Type = (SELECT TYPE FROM INV WHERE ITEM = @Item)
IF(@InventoryQuantityAddSubtract = 0) --Add
BEGIN
EXEC InventoryQuantityAdd_Update @Type,@Qty,@Item
END
ELSE IF(@InventoryQuantityAddSubtract = 1)--Subtract
BEGIN
EXEC InventoryQuantitySubtract_Update @Type,@Qty,@Item
END
--COMMIT TRAN
END
how would I be able to do this using table valued parameters
Debra has a question