Domanda

I have a stored procedure, which when I execute it, I got this result:

enter image description here

I want to get a specific columns using another stored procedure.

How can I do that?

What I have thought

Creating a new temporary table and fill the two columns in it. But the stored procedure returns more than 3 billion rows. So, it is not a good performance to create a temporary table for them.

If it is the only solution please tell me

Second idea

I can't change the stored procedure because I only have permission to execute it not to modify it. So, the solution has to be in the stored procedure that I will write not in the stored procedure that I execute and that I can't modify.

È stato utile?

Soluzione

I guess you could use the OPENROWSET to execute and get only the required Column.

SELECT ColumnName    --<-- The columns required.
FROM 
 OPENROWSET('SQLNCLI'
            ,'Server=ServerName\InstanceName;Trusted_Connection=yes;database=DatabaseName'
            ,'EXECUTE dbo.Proc_Name')

UPDATE

As it says in the error message this feature is turned off by default in sql server. you need to allow by executing the following system stored procedures..

EXECUTE sp_configure 'Show Advanced Options', 1
GO
RECONFIGURE
GO
EXECUTE sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
GO

Altri suggerimenti

Either way, I beleive if you execute a stored procedure, SQL Server will run the whole thing (all the rows and columns will have to get returned), unless it takes some params which trim it. Only then can you extract what you want from it. It doesn't really matter whether you use a temp table or openrowset at that point to get what you want from it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top