Friday, July 16, 2010

Execute stored proc into a temp table

Ever want to select the results from a sproc into a temp table? Why you might
ask? Sometimes I do not have access to the source (encrypted), or it is on a
production system and I am not able to crack it open to run it bit by bit, and
have only the option of running the sproc plain vanilla. Here is the code to
capture it into a temp table (no need to worry about declaring the table). Only
catch is openrowset settings need to be enabled.

FROM OPENROWSET('SQLNCLI','Server=(local);Trusted_Connection=yes;',
               'EXEC [database].[schema].[stored proc]')

No comments:

Post a Comment