SQL SERVER 2012 – Fix – Error :11513 – The metadata could not be determined because statement contains dynamic SQL. Consider using the WITH RESULT SETS clause to explicitly describe the result set.


SQL Server Portal

Dynamic SQL queries are one of my favorite queries when it comes to handling multiple conditions from a single query. But it should be handled very carefully. The error we will discuss in this article is related to dynamic SQL and sp_describe_first_result_set, a new system stored procedure shipped with SQL Server 2012. This error message is available in SQL Server 2012 and above.

Let’s discuss this in detail:
Message Number: 11513

Severity : 16

Error Message: The metadata could not be determined because statement ‘%.*ls’ contains dynamic SQL. Consider using the WITH RESULT SETS clause to explicitly describe the result set.

Error Generation:
Let me create a sample to demonstrate this error. In this sample, I need to dynamically select few columns from [HumanResources].[vEmployee] (View).

Errormsg11513.1.1

You can see that the above script executed successfully. Now I would like to view the metadata of the above dynamic SQL query. Given…

View original post 119 more words