Groups | Blog | Home
all groups > sql server mseq > february 2004 >

sql server mseq : Execute a stored procedure and place results in a temporary table



Alastair Bell
2/24/2004 9:26:05 AM
Could someone please advise me on the syntax in Transact SQL to execute a stored procedure (that returns records) and then place the results in a temporary table

Vishal Parkar
2/24/2004 11:32:18 PM
hi alastair,

--Two methods
1) you will have to create a table first and then insert output of stored procedure using
following syntax.

insert into <table> exec <stored_procedure>

create table #t(
spid int null,
ecid int null,
status varchar(500) null,
loginname varchar(500) null,
hostname varchar(500) null,
blk int null,
dbname sysname null,
cmd varchar(800) null)

insert into #t exec sp_who

2) without precreating the table you will have something as follows

EXEC sp_serveroption <server name>, 'data access' , 'true'

select *
into #temptable
from openquery (<server name>, 'exec sp_who')



--
Vishal Parkar
vgparkar@yahoo.co.in


Alastair Bell
2/25/2004 3:36:05 AM
AddThis Social Bookmark Button