elena1234

Stored Procedures ( T-SQL )

Mar 27th, 2022 (edited)
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.96 KB | None | 0 0
  1. USE [AdventureWorks2019]
  2. GO
  3.  
  4.  
  5. -- Exercise
  6. -- Create a stored procedure called "OrdersAboveThreshold" that pulls in all sales orders with a total due amount
  7. -- above a threshold specified in a parameter called "@Threshold".
  8. -- The value for threshold will be supplied by the caller of the stored procedure.
  9. -- The proc should have two other parameters: "@StartYear" and "@EndYear" (both INT data types),
  10. -- also specified by the called of the procedure. All order dates returned by the proc should fall between these two years.
  11.  
  12. CREATE PROCEDURE dbo.OrdersAboveThreshold (@Threshold MONEY, @StartYear INT, @EndYear INT)
  13. AS
  14. BEGIN
  15.     SELECT
  16.         A.SalesOrderID,
  17.         A.OrderDate,
  18.         A.TotalDue
  19.  
  20.     FROM  AdventureWorks2019.Sales.SalesOrderHeader A
  21.         JOIN AdventureWorks2019.dbo.Calendar B
  22.             ON A.OrderDate = B.DateValue
  23.  
  24.     WHERE A.TotalDue >= @Threshold
  25.         AND B.YearNumber BETWEEN @StartYear AND @EndYear
  26. END
  27.  
  28. GO
  29.  
  30.  
  31. EXEC dbo.OrdersAboveThreshold 10000, 2011, 2013
  32.  
  33.  
Add Comment
Please, Sign In to add comment