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

Question

$
0
0

How would I be able to do this? I would like to update a table called ARH based on a user defined table type. For each row in the user defined table I would like to get the @PaidInvoice (see #2) which checks based on this invoice number any time it was applied to, to get the full amount that was paid to this invoice. I would like to somehow put that code into the merge. Is that possible?

   1. MERGE INTO ARH target
        USING (SELECT [OPEN] FROM @ApplyPayment) AS source
        ON target.INVOICE = source.Invoice
        WHEN MATCHED THEN 
        UPDATE 
        SET [Open] = source.[Open], CloseDate = Case source.[Open] WHEN 'TRUE' THEN NULL WHEN 'FALSE' THEN CONVERT(DATE, GETDATE()) END, PAID =@PaidInvoice; 
    
  2.  DECLARE @PaidInvoice decimal(10,2)
    SET @PaidInvoice = 
    (SELECT SUM(TOTAL.AMOUNT) FROM(SELECT AMOUNT FROM APPLIED WHERE INVOICE = @Invoice
UNION ALL SELECT AMOUNT FROM CREDITMEMO WHERE INVOICE = @Invoice)TOTAL)


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>