I have the problem that I need to know the columns of any stored procedure that passes as a parameter inside another. But in any case I do not get any results.
ALTER PROCEDURE getColumnsTable
(@tableColumnsNames nvarchar(45))
AS
BEGIN
DECLARE @TSQL varchar(100)
SET @TSQL = 'select * into #TablaTemporal FROM OPENQUERY( MyServerConnection, ''EXEC '+ @tableColumnsNames +''');'
EXEC (@TSQL)
SELECT COLUMN_NAME
FROM tempdb.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME like '%#TablaTemporal%'
IF EXISTS (SELECT * FROM tempdb.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME like '%#TablaTemporal%' )
BEGIN
DROP TABLE #TablaTemporal
END
END
This is the stored procedure I would like to read
ALTER PROCEDURE MyProcTest
AS
BEGIN
SET NOCOUNT ON;
SELECT
c.idCliente, f.idFactura
FROM
Cliente c
INNER JOIN
Factura f ON (c.idCliente = f.idCliente)
WHERE
1 = 2
END
I would like to obtain a
COLUMN_NAME
idCliente
idFactura
from a simple
EXEC getColumnsTable @tableColumnsNames = N'MyProcTest'
Is this possible? I have not found the solution.
SQL Server 2008: cas you try like this:
SQL 2012 and up: you can use DMV sys.dm_exec_describe_first_result_set_for_object
Example: