[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

SQL Server insert with loop

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
dodgerfan
Asked:
dodgerfan
1 Solution
 
Ephraim WangoyaCommented:


insert into table2 (col1, col2, col3, ...)
select col1, col2, col3, ...
from table1
0
 
dodgerfanAuthor Commented:
Perfect, thanks.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now