Sql Server: Insert Stored Procedure Results Into Table
- Posted by Sqltimes
- On November 18, 2013
- 0 Comments
Quick one today:
To insert the output of a stored procedure into a temporary table, I use the following steps.
- Create a temporary table with necessary table structure
- Execute the Stored procedure while inserting its output into this table.
Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
-- -- Create Temporary Table -- DROP TABLE #who2 GO CREATE TABLE #who2 ( SPID varchar (255) , Status varchar (255) , Login varchar (255) , HostName varchar (255) , BlbBy varchar (255) , DBName varchar (255) , Command varchar (255) , CPUTime varchar (255) , DiskIO varchar (255) , LastBatch varchar (255) , ProgramName varchar (255) , SPID2 varchar (255) , RequestID varchar (255) ); GO -- -- Query stored procedure results into the temporary table -- INSERT #who2 Exec sp_who2; GO select * from #who2; GO |
Hope this helps,
_Sqltimes
0 Comments