views:

64

answers:

1

I wish to do the following:

select * into tmptbl from sometable

EXCEPT 'sometable' is a stored procedure that returns a result set AND editing the stored procedure to suit my goal is not an option. ALSO i may or may not know the columns and types of what the procedure returns.

Basically i am looking for a proper way of doing this:

select * into tmptbl from exec someSP

Is this even possible, if so, how?

+3  A: 

yes it is possible with a loopback query like this

SELECT * INTO #tmptbl 
    FROM OPENROWSET ('SQLOLEDB','Server=(local);TRUSTED_CONNECTION=YES;'
   ,'set fmtonly off exec DatabaseName.dbo.someSP')

More example here: Store The Output Of A Stored Procedure In A Table Without Creating A Table

Be aware that this has to be turned on first, see here: How to enable xp_cmdshell and Ad Hoc Distributed Queries on SQL Server 2005

SQLMenace
I was just writing the same thing. It's not pretty, but it works.
kcrumley
no good, 'Ad Hoc Distributed Queries' are not enabled and i am not an admin.
LoudNPossiblyRight
That is the only way I know of
SQLMenace
This works however this has to be done first on a default installation:exec sp_configure 'show advanced options', 1;RECONFIGURE;exec sp_configure 'Ad Hoc Distributed Queries', 1;RECONFIGURE;GO;Ugly but it works, thank you :)
LoudNPossiblyRight
Yes, see also here http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/how-to-enable-xp_cmdshell-on-sql-server-2005
SQLMenace