Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote