EXECUTE statement failed because its WITH RESULT SETS clause specified %d result set(s), but the statement only sent %d result set(s) at run time is one of the new error messages seen in SQL Server 2012. This error message is due to the invalid use of new feature EXEC WITH RESULT SETS.
Let’s discuss this in detail:
Message Number: 11536
Severity : 16
Error Message: EXECUTE statement failed because its WITH RESULT SETS clause specified %d result set(s), but the statement only sent %d result set(s) at run time.
Error Generation:
Let me create a sample stored procedure to generate this error.
Create Procedure UDP_Resultset As Select 'A' as [First Letter] Select 'B' as [Second Letter] GO EXEC UDP_Resultset
You can see that the above stored procedure is executed successfully and it has two result sets.
Lets try to execute it with WITH RESULT SETS clause.
EXEC UDP_Resultset WITH RESULT SETS (([1st Letter] varchar(50) ) ,([2nd Letter] varchar(50) ) ,([3rd Letter] varchar(50) ) ); --OUTPUT
EXECUTE statement failed because its WITH RESULT SETS clause specified 3 result set(s), but the statement only sent 2 result set(s) at run time.
Ooops…… I am unable to execute it properly. It returned the two result sets and the error message.
Resolution:
Why this error ? Because, the above stored procedure returns two result sets but we defined WITH RESULT SETS clause for three result sets. Lets rewrite the script and define two result sets (The same number of result sets returned by stored procedure) to avoid this error.
EXEC UDP_Resultset WITH RESULT SETS (([1st Letter] varchar(50) ) ,([2nd Letter] varchar(50) )); --OUTPUT
Conclusion :
Remember, whenever you use any stored procedure WITH RESULT SETS clause, make sure you use exactly the same number of result set returned by stored procedure to avoid such errors.
How can we configure the result set when there will be an unknown number of column coming from the called store proc – ie each column being different date from the prevous year