?
Solved

insert into using exec proc

Posted on 2003-12-05
4
Medium Priority
?
1,935 Views
Last Modified: 2008-02-01
Hi,

Is it possible to insert into a temp table, the results from exec'ing a stored proc?

i.e.

insert into #temp1(col1, col2, col3...)
 exec myProc

Cheers, Andy
0
Comment
Question by:amtate
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Expert Comment

by:ChrisKing
ID: 9886670
That is a MS-SQL extention that is not (yet) supported in Sybase.
However I too would have some uses for it whenit comes.
0
 
LVL 15

Expert Comment

by:namasi_navaretnam
ID: 9893081
Chris is right. However, you can insert the final result into a temp table before exiting the proc and access the same temp table within the parent proc.

Example:

Create procedure sp_test
As
Begin
-- Final Step before exiting
insert into #temptable (col1, col2)
select col1, col2
from MyTable
End

--Parent Proc
Create Proc sp_Parent
As
Begin

exec sp_test

select * from #temptable

End


HTH

Namasi Navaretnam.
0
 
LVL 15

Accepted Solution

by:
namasi_navaretnam earned 1500 total points
ID: 9894488
One more point I should add, to make sp_Parent compile you will need to create #temptable outside the procedure.

create table #temptable
(
col1 int,
col2 varchar(100),
coletc int
)

go
--Parent Proc
Create Proc sp_Parent
As
Begin

exec sp_test

select * from #temptable

End

go
Drop table #temptable
go

HTH

Namasi Navaretnam

0
 

Author Comment

by:amtate
ID: 9895371
Thanks Namasi - this was helpful...

Rgds, Andy
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question