QuestionQ7

Secure, optimize, and deploy database solutions

You have an Azure SQL database containing a table named dbo.Orders. dbo.Orders has a CreateDate column that stores order-creation dates.

You need to create a stored procedure that filters Orders by CreateDate for one calendar day. The solution must be SARGable.

How should you complete the Transact-SQL code? Each value may be used once, more than once, or not at all.

Drag & Drop
CREATE PROCEDURE dbo.usp_SearchOrders
    @StartDate date
AS
BEGIN
    SET NOCOUNT ON;

    DECLARE @EndDate date;

    SET @EndDate = 

    SELECT  o.CreateDate,
            o.OrderId,
            o.ShipDate
    FROM    dbo.Orders AS o
    WHERE   o.CreateDate >= 
      AND   o.CreateDate <  ;
END;
GO
Explanation

A SARGable date filter compares CreateDate directly to range boundaries rather than applying CONVERT to CreateDate. DATEADD(day, 1, @StartDate) supplies the exclusive next-day boundary, so the >= and < predicates return every timestamp on the specified calendar day.

Community Discussion

No comments yet. Be the first to start the discussion!