Solved

insert from exec

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

exec sp_selecttable
0
Comment
Question by:sevensnake77
  • 2
  • 2
4 Comments
 
LVL 9

Author Comment

by:sevensnake77
ID: 37738440
So example would be

Insert Into [table1]

exec sp_selecttable
0
 
LVL 39

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 39

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

772 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