Problem 3 (6 points) - Fill in the missing code: CREATE PROCEDURE dbo.[Year to Y
ID: 3537274 • Letter: P
Question
Problem 3 (6 points) - Fill in the missing code:
CREATE PROCEDURE dbo.[Year to Year Sales]
@BeginDate DateTime = Null,
@EndDate DateTime = Null
____
IF @BeginDate IS Null
SET @BeginDate = dateadd(yy,-1,GetDate())
IF @EndDate IS Null
SET @EndDate = GetDate()
IF Datediff(dd,@BeginDate,@EndDate) > 365
________ 50001,'The maximum timespan allowed is one year.', 1;
ELSE
SELECT O.ShippedDate,O.OrderID,OS.Subtotal, DATENAME(yy,ShippedDate) AS Year
_______ ORDERS O INNER JOIN [Order Subtotals] OS
____ O.OrderID = OS.OrderID
WHERE O.ShippedDate
BETWEEN @BeginDate AND @EndDate;
GO
Explanation / Answer
CREATE PROCEDURE dbo.[Year to Year Sales]
@BeginDate DateTime = Null,
@EndDate DateTime = Null
BEGIN
IF @BeginDate IS Null
SET @BeginDate = dateadd(yy,-1,GetDate())
IF @EndDate IS Null
SET @EndDate = GetDate()
IF Datediff(dd,@BeginDate,@EndDate) > 365
________ 50001,'The maximum timespan allowed is one year.', 1;
ELSE
SELECT O.ShippedDate,O.OrderID,OS.Subtotal, DATENAME(yy,ShippedDate) AS Year
FROM ORDERS O INNER JOIN [Order Subtotals] OS
ON O.OrderID = OS.OrderID
WHERE O.ShippedDate
BETWEEN @BeginDate AND @EndDate;
GO
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.