Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --1.
- Declare @TotalDue money;
- Set @TotalDue = (Select Sum(InvoiceTotal - PaymentTotal - CreditTotal) From Invoices);
- If @TotalDue < 10000
- Print 'Balance due is less than $10,000.'
- Else
- Select VendorName, InvoiceNumber, InvoiceDueDate, InvoiceTotal - PaymentTotal - CreditTotal As Balance
- From Vendors Join Invoices On Vendors.VendorID = Invoices.VendorID
- Where InvoiceTotal - PaymentTotal - CreditTotal > 0
- Order By InvoiceDueDate asc
- --2.
- Declare @VendorV table(name varchar(50), countv int, total money);
- Insert @VendorV
- Select Distinct VendorName As name, Count(*) As countv, Sum(PaymentTotal) As total
- From Vendors Join Invoices On Vendors.VendorID = Invoices.VendorID
- Group By VendorName
- Having Count(*) > 1
- Select * From @VendorV
- Order By countv desc
- --3.
- BEGIN TRY
- INSERT Vendors
- VALUES ('UC Blue Ash', '9555 Plainfield Rd', NULL,
- 'Blue Ash', 'OH', 45236, NULL, 'Eckert', 'Chris', NULL, NULL);
- PRINT 'SUCCESS: Record was inserted.';
- END TRY
- BEGIN CATCH
- PRINT 'FAILURE: Record was not inserted.';
- PRINT 'Error '
- + CONVERT(varchar, ERROR_NUMBER())
- + ': '
- + ERROR_MESSAGE();
- END CATCH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement