Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Sql complex query with table valued parameters

$
0
0

I have a list of invoices in the form of a work order which I would like to convert to an invoice. This entails: 

USE [Trial]
GO
/****** Object:  StoredProcedure [dbo].[SaveAsInvoice_Update]    Script Date: 02/27/2014 15:21:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:Debra
-- Create date: December 25, 2013
-- Description:Update work orders to invoices
-- =============================================
ALTER PROCEDURE [dbo].[SaveAsInvoice_Update] 
-- Add the parameters for the stored procedure here
@Invoice int,
@ARHIDs AS IntListUDTT READONLY --table valued parameter
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

    -- Insert statements for procedure here
    UPDATE ARH SET INVOICE = @Invoice, STATUS = 'inv' WHERE ARHID IN (SELECT ID FROM @ARHIDs)
END

I also need to update inventory since a work order does not affect inventory but an invoice does. I need to get all the items from all these invoices (since you can update more than one work order to invoice at a time), and get there qty and update inventory based on that. Would I have to do a loop or can I do a join somehow or something else?



Debra has a question


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>