Solved

insert from exec

Posted on 2012-03-19
4
416 Views
Last Modified: 2012-03-19
Is it possible to have an insert statement but using

exec sp_selecttable
0
Comment
Question by:sevensnake77
[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
  • 2
4 Comments
 
LVL 9

Author Comment

by:sevensnake77
ID: 37738440
So example would be

Insert Into [table1]

exec sp_selecttable
0
 
LVL 40

Assisted Solution

by:lcohan
lcohan earned 300 total points
ID: 37738601
Yes, you must create the table first matching the record set from your SP so assume your SP returns

id int, name varchar(50), address varchar(100)

you create atable like:

create #temp_table (id int, name varchar(50), address varchar(100));
insert into #temp_table exec sp_whatever;
0
 
LVL 40

Accepted Solution

by:
lcohan earned 300 total points
ID: 37738612
Sorry one minor syntax error above and you can do the same with a permanent database table not just temporary table:

create table #temp_table (id int, name varchar(50), address varchar(100));
insert into #temp_table exec sp_selecttable;
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 37738667
tks
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

696 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