Querying Data with Transact-SQL — Question 123

You are building a stored procedure that will update data in a table named Table1 by using a complex query as the data source.
You need to ensure that the SELECT statement in the stored procedure meets the following requirements:
✑ Data being processed must be usable in several statements in the stored procedure.
✑ Data being processed must contain statistics.
What should you do?

Answer options

Correct answer: B

Explanation

The correct answer is B because inserting the data into a temporary table allows for the data to be used multiple times in the stored procedure and also for statistics to be collected. Option A does not guarantee the data's usability in several statements since CTEs are not stored. Option C may not provide the necessary statistics, as derived tables do not maintain them, and option D lacks the ability to utilize statistics effectively.