Friday, July 21, 2017

Check the Data Type plus other details of each column in the Stored Procedure Result in SQL Server

//Shows the list of each column with details, that are returned from the Stored Procedure in SQL Server

For instance, there is Stored Procedure SprocGetUsersList. Now, if User wants to see the data type of each column in the list returned from that Proc, here's solution:

SELECT p.name, r.*
FROM sys.procedures AS p
CROSS APPLY sys.dm_exec_describe_first_result_set_for_object(p.object_id, 0) AS r
where p.name='SprocGetUsersList';
GO


Compatibility:
yesSQL Server (starting with 2012)yesAzure SQL Database


References: 

https://docs.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-exec-describe-first-result-set-for-object-transact-sql