Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

insert from exec

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

exec sp_selecttable
0
Comment
Question by:Seven price
[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:Seven price
ID: 37738440
So example would be

Insert Into [table1]

exec sp_selecttable
0
 
LVL 40

Assisted Solution

by:lcohan
lcohan earned 1200 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 1200 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:Seven price
ID: 37738667
tks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

610 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