Advertisement
Avacor

Untitled

Jan 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.59 KB | None | 0 0
  1. --Declares Variable Total Outstanding as money
  2. DECLARE @TotalOutstanding money;
  3.  
  4. --Initilizes the Total Outstanding
  5. SELECT @TotalOutstanding = SUM(InvoiceTotal - CreditTotal - PaymentTotal)
  6. FROM Invoices
  7.     WHERE InvoiceTotal - CreditTotal - PaymentTotal > 0;
  8.  
  9. IF @TotalOutstanding > 10000
  10.     SELECT VendorName, InvoiceNumber, InvoiceDueDate,
  11.     InvoiceTotal - CreditTotal - PaymentTotal AS Balance
  12.     FROM Invoices JOIN Vendors ON Invoices.VendorID = Vendors.VendorID
  13.         WHERE InvoiceTotal - CreditTotal - PaymentTotal > 0
  14.         ORDER BY InvoiceDueDate;
  15. ELSE
  16. PRINT 'Balance due is less than $10,000.00.';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement