Subdomain 1.2: Implement programmability objects
1.You need to create a reusable routine that calculates the number of business days between two dates, to be used in SELECT, WHERE, and ORDER BY clauses across multiple queries and views. The routine must accept two date parameters and return an integer. Which type of programmability object should you create?
- A.A stored procedure with output parameter.
- B.A scalar user-defined function (UDF).
- C.A view with a computed column.
- D.A table-valued function (TVF).
Show answer & explanation
Correct answer: B — A scalar user-defined function (UDF).
- A. Incorrect. A stored procedure with an output parameter can return a value, but it cannot be used directly in SELECT, WHERE, or ORDER BY clauses. Stored procedures are executed as standalone statements and do not return values inline in queries.
- B. Correct. A scalar user-defined function accepts parameters, performs calculations, and returns a single scalar value such as an integer. Because it can be used like an expression, it is appropriate for use in SELECT, WHERE, and ORDER BY clauses across multiple queries and views.
- C. Incorrect. A view does not accept parameters, so it cannot directly take two date inputs to calculate business days. A computed column also cannot provide a reusable parameterized routine across different queries and views.
- D. Incorrect. A table-valued function returns a table result set, not a single integer. Although functions can be used in queries, this requirement specifically says the routine must return an integer, which fits a scalar function rather than a table-valued one.