SHARE
TWEET

Untitled

a guest Feb 17th, 2017 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Trigger Loan Confirmation
  2. CREATE TRIGGER trgThankyou
  3. ON Loan
  4. AFTER INSERT
  5. AS
  6. BEGIN
  7.     DECLARE @newLoanID INT = (SELECT TOP 1 loanID FROM Loan ORDER BY loanID DESC) --Getting the newest loan created
  8.     DECLARE @itemTitle NVARCHAR(MAX) = (SELECT title FROM Item  --Getting the title of the book or dvd
  9.                 JOIN Loan ON Item.itemID = Loan.itemID
  10.                 WHERE Loan.loanID = @newLoanID)
  11.     DECLARE @dueDate DATE = (SELECT dueDate FROM Loan WHERE loanID = @newLoanID); --Getting the due date
  12.     --Prints to display info to the user
  13.     PRINT 'Order Number: '+CAST (@newLoanID AS VARCHAR(MAX));
  14.     PRINT 'You have loaned: '+@itemTitle;
  15.     PRINT 'It is due: '+CAST (@dueDate AS VARCHAR(MAX));
  16. END
  17. GO
RAW Paste Data
Top