Advertisement
Guest User

Untitled

a guest
Nov 12th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.44 KB | None | 0 0
  1. -- Question 1 --
  2. SELECT Rental.rentalID, Make.carMakeName, Model.carModelName
  3. FROM Rental
  4. INNER JOIN Car ON Car.carID = Rental.carID
  5. INNER JOIN Car_Model AS Model ON Car.carModelID = Model.carModelID
  6. INNER JOIN Car_Make AS Make ON Model.carMakeID = Make.carMakeID;
  7.  
  8. -- This join could be used to check what the most common cars rented in order to make future
  9. -- purchase decisions
  10.  
  11. -- Question 2 --
  12. CREATE PROC FordReturnDates
  13. AS
  14. SELECT Rental.rentalID, Make.carMakeName, Rental.dueDate
  15. FROM Rental
  16. INNER JOIN Car ON Car.carID = Rental.carID
  17. INNER JOIN Car_Model AS Model ON Car.carModelID = Model.carModelID
  18. INNER JOIN Car_Make AS Make ON Model.carMakeID = Make.carMakeID
  19. WHERE Make.carMakeName LIKE 'Ford';
  20.  
  21. EXEC dbo.FordReturnDates;
  22.  
  23. -- This Stored Procedure can be used to return the due dates of all Fords currently rented.
  24. -- This is useful if a customer is requesting a Ford Vehicle for an upcoming trip
  25.  
  26. -- Question 3 --
  27. DECLARE @CustomerBirthday as DATE;
  28.  
  29. DECLARE @BirthdayCursor as CURSOR;
  30. SET @BirthdayCursor = CURSOR FOR
  31. SELECT birthDate
  32. FROM Customer
  33. WHERE birthDate IS NULL;
  34.  
  35. OPEN @BirthdayCursor;
  36.  
  37. FETCH NEXT FROM @BirthdayCursor INTO @CustomerBirthday;
  38.  
  39. WHILE @@FETCH_STATUS = 0
  40. BEGIN
  41.     PRINT @CustomerBirthday;
  42.     FETCH FROM @BirthdayCursor INTO @CustomerBirthday
  43. END
  44.  
  45. CLOSE @BirthdayCursor;
  46. DEALLOCATE @BirthdayCursor;
  47. -- This cursor can be used to check that all customers have the birthdate field filled in.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement