Solved

SQL Server insert with loop

Posted on 2011-03-08
2
457 Views
Last Modified: 2012-05-11
I need to insert records into a table in SQL Server 2008. I want to insert the records from an existing table. So for each record in table1, insert that record into table2. The tables are not exact matches. I want to copy the correct data into the new table. What would be the best way to do this?
0
Comment
Question by:dodgerfan
2 Comments
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
ID: 35073257


insert into table2 (col1, col2, col3, ...)
select col1, col2, col3, ...
from table1
0
 

Author Closing Comment

by:dodgerfan
ID: 35074154
Perfect, thanks.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now