β’ A multi-statement table-valued function (TVF) named sales.mstvf_orderStatus() that returns order status information
β’ A scalar user-defined function (UOF) named dbo.ufn_GetlaxMultiplier(^rax/Wt money,
gStateCode char(2)) that returns a numeric multiplier used in tax calculations Reporting queries frequently join Sales.Β«istvf_OrderStatus() to a table named Sales.SalesOrderHeader and return large result sets. A performance review shows that the queries produce inconsistent execution plans.
During a code review, a developer discovers that the following Transact-SQL statement produced an error.

Show answerHide answer
Explanation

Explanation:
This question tests your understanding of T-SQL user-defined functions, specifically the rules for determinism, the performance differences between Multi-Statement Table-Valued Functions (MSTVFs) and Inline TVFs, and the mandatory syntax for invoking scalar functions. The scenario highlights an execution error in a scalar function call and inconsistent execution plans caused by an MSTVF join.
βοΈ Correct Option:
Statement 3 (Yes):
Replacing ufn_GetTaxMultiplier with dbo.ufn_GetTaxMultiplier in the EXEC function statement will resolve the error. In SQL Server and Microsoft Fabric, scalar user-defined functions must be invoked using at least a two-part name (schema.function_name). The original statement lacked the schema prefix, which is the exact cause of the execution error. Adding dbo. correctly resolves the function name and fixes the issue.
β Incorrect Options:
Statement 1 (No):
You cannot use GETDATE() in dbo.ufn_GetTaxMultiplier to produce nondeterministic results. While GETDATE() is a nondeterministic function, its inclusion does not "produce" nondeterministic results in a way that fixes an error or is the intended design here. Furthermore, the error in the code is a syntax/resolution error (missing schema), not an issue with function determinism.
Statement 2 (No):
Rewriting Sales.mstvf_OrderStatus() as an inline TVF will not reduce the number of inconsistent execution plans. Inline TVFs allow the query optimizer to expand them into the outer query, which generally improves cardinality estimation and results in more stable and consistent execution plans compared to MSTVFs. Therefore, the statement's claim is logically inverted and incorrect.
π§ Reference:
β Execute user-defined functions - Confirms that scalar functions must be invoked using a two-part name (schema.function).
β Create Table-Valued Functions - Explains how inline TVFs provide better optimization and stable execution plans compared to multi-statement TVFs.


.png)







