Microsoft Fabric Data Engineer Associate DP-700 Practice Question
You author the following T-SQL in a Microsoft Fabric warehouse and receive an error at compile time:
CREATE OR ALTER PROCEDURE dbo.usp_GetSales
@StartDate date,
@EndDate datetime = DATEADD(day,-7,CURRENT_TIMESTAMP)
AS
SELECT *
FROM dbo.Sales
WHERE SaleDate BETWEEN @StartDate AND @EndDate;
You want callers to be able to omit @EndDate so that it automatically defaults to seven days before the current time. Which modification will resolve the error while preserving this behaviour?
Fully qualify the DATEADD function by writing dbo.DATEADD(day,-7,CURRENT_TIMESTAMP) in the parameter list.
Delete the default expression and begin the procedure with:
IF @EndDate IS NULL
SET @EndDate = DATEADD(day,-7,CURRENT_TIMESTAMP);
Add the query hint OPTION (ENABLE_VARIABLE_FUNCTIONS = 1) at the end of the SELECT statement.
Change the default to a literal value, for example @EndDate datetime = '2024-01-01'.
In T-SQL a parameter's default value must be a literal constant or NULL; expressions that invoke variables or scalar functions such as GETDATE or DATEADD are not allowed in the parameter list. To keep the desired dynamic logic you must remove the expression from the declaration, allow the parameter to be nullable, and assign the calculated value inside the procedure body. Changing the default to a literal date would compile but would not provide a rolling 7-day window, and no query or session option enables function calls in parameter defaults. Qualifying DATEADD with a schema also makes no difference because the syntax rule-not object resolution-is the source of the error. Therefore, setting the default to NULL and calculating the value after the procedure starts is the correct fix.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
Why can't we use expressions like DATEADD in T-SQL parameter defaults?
Open an interactive chat with Bash
What is the difference between setting a default value in the parameter list vs inside the procedure body?
Open an interactive chat with Bash
What happens when we try to compile a stored procedure with a function-based default parameter value?
Open an interactive chat with Bash
Microsoft Fabric Data Engineer Associate DP-700
Monitor and optimize an analytics solution
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99
$19.99/mo
Billed monthly, Cancel any time.
3 Month Pass
$44.99
$14.99/mo
One time purchase of $44.99, Does not auto-renew.
MOST POPULAR
Annual Pass
$119.99
$9.99/mo
One time purchase of $119.99, Does not auto-renew.
BEST DEAL
Lifetime Pass
$189.99
One time purchase, Good for life.
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .