Querying Microsoft SQL Server 2012/2014 — Question 9
Your application contains a stored procedure for each country. Each stored procedure accepts an employee identification number through the @EmpID parameter.
You need to build a single process for each employee that will execute the appropriate stored procedure based on the country of residence.
Which approach should you use?
Answer options
- A. A SELECT statement that includes CASE
- B. Cursor
- C. BULK INSERT
- D. View
- E. A user-defined function
Correct answer: E
Explanation
The correct answer is E, as a user-defined function can encapsulate the logic to determine the appropriate stored procedure to execute based on the country. The other options are not suitable; a SELECT statement with CASE would not execute procedures, a cursor is used for iterative processing, BULK INSERT is for data loading, and a view is for presenting data rather than executing logic.