Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. --1.
  2. Declare @TotalDue money;
  3. Set @TotalDue = (Select Sum(InvoiceTotal - PaymentTotal - CreditTotal) From Invoices);
  4. If @TotalDue < 10000
  5. Print 'Balance due is less than $10,000.'
  6. Else
  7. Select VendorName, InvoiceNumber, InvoiceDueDate, InvoiceTotal - PaymentTotal - CreditTotal As Balance
  8. From Vendors Join Invoices On Vendors.VendorID = Invoices.VendorID
  9. Where InvoiceTotal - PaymentTotal - CreditTotal > 0
  10. Order By InvoiceDueDate asc
  11.  
  12. --2.
  13. Declare @VendorV table(name varchar(50), countv int, total money);
  14. Insert @VendorV
  15. Select Distinct VendorName As name, Count(*) As countv, Sum(PaymentTotal) As total
  16. From Vendors Join Invoices On Vendors.VendorID = Invoices.VendorID
  17. Group By VendorName
  18. Having Count(*) > 1
  19.  
  20. Select * From @VendorV
  21. Order By countv desc
  22.  
  23. --3.
  24. BEGIN TRY
  25. INSERT Vendors
  26. VALUES ('UC Blue Ash', '9555 Plainfield Rd', NULL,
  27. 'Blue Ash', 'OH', 45236, NULL, 'Eckert', 'Chris', NULL, NULL);
  28. PRINT 'SUCCESS: Record was inserted.';
  29. END TRY
  30.  
  31. BEGIN CATCH
  32. PRINT 'FAILURE: Record was not inserted.';
  33. PRINT 'Error '
  34. + CONVERT(varchar, ERROR_NUMBER())
  35. + ': '
  36. + ERROR_MESSAGE();
  37. END CATCH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement