Sunday, September 27, 2009

How to insert the result set of a store proc or dynamic batch into a new table using SELECT INTO?

Hi Readers,

Thank you for sending emails.I appreciate it.Now let do some coding.

Suppose you want to insert the result set of a store procedure or a dynamic batch into
a new table,but you do not know what the schema is that you need to create.
You can use SELECT INTO statement and OPENQUERY.Here is how it works:

1-SELECT INTO format

SELECT
INTO
FROM

ex:
SELECT CustomerID,CompanyName,Country
INTO US_Customers
FROM Northwind.dbo.Customers

NB Do not create US_Customers in Nort
hwind database before executing the query.This table
US_Customers is created automatically for you after query execution.

2-The main query of concern(see title)

EXEC sp_serveroption,'data access',true;
SELECT *INTO FROM OPENQUERY(,'EXEC {(

That`s all i want to share with you today.
See you!

Talley Ouro
.Net Developer(Web&Smart Client Development)
Email: johnstalley@live.com



No comments:

About Me

My photo
Raleigh, NC, United States
I am a software developer based in Raleigh,NC,USA.I design softwares and systems ;i also do consulting for companies worldwide.I program with these languages:VB.NET 2003/2005/2008;C#;Java(fun),SQL(200,2005,2008);ASP.NET 2.0/3.5;ASP.NET AJAX;ASP.NET MVC;JavaScript;JQuery;Windows Workflow Foundation;Web Services.I have 4 years + in programming.