Querying Data with Transact-SQL — Question 143
Note: This question is part of a series of questions that use the same or similar answer choices. An answer choice may be correct for more than one question in the series. Each question is independent of the other questions in this series. Information and details provided in a question apply only to that question.
You have a database that stores sales and order information.
Users must be able to extract information from the tables on an ad hoc basis. They must also be able to reference the extracted information as a single table.
You need to implement a solution that allows users to retrieve the data required, based on variables defined at the time of the query.
What should you implement?
Answer options
- A. the COALESCE function
- B. a view
- C. a table-valued function
- D. the TRY_PARSE function
- E. a stored procedure
- F. the ISNULL function
- G. a scalar function
- H. the TRY_CONVERT function
Correct answer: C
Explanation
The correct answer is C, a table-valued function, because it allows users to pass parameters and return a table of results based on those parameters. Other options, such as views and stored procedures, do not provide the same level of flexibility for returning a table directly based on variable input during a query.