Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copying Data from one table to another Sql Server 2005

Posted on 2009-07-08
5
Medium Priority
?
193 Views
Last Modified: 2012-05-07
Good afternoon,

I've got a table "Labor" that has existing employees hours in it.  I have created another table called "LaborReport" that needs to have all the data existing in Labor transfered to it.  It has all the same columns, minus it's own unique identifying column.

The columns in Labor are:
LaborId
JobId
EmployeeId
LaborDate
LaborHoursWorked
EmployeeRoleId
TimeTypeId
LaborNotes
LaborPeriodFrom
LaborPeriodTo
CreatedBy
CreatedDt
UpdatedBy
UpdatedDt

The columns in LaborReport except it has an added column called "ID"

What's the easiest way to get all the data from one to the other?  Is there a query I could write that would do it?

Also this only needs to be a one time transfer, I have the triggers that will keep the two tables the same after I can get all the existing data in there already.

While I'm very famliar with coding and accessing data in a database, I'm really novice when it comes to doing things inside a database.. so I'm assuming there has to be an easy way to do this rather than having to code a function to loop through and grab all the records, store the data in variables, then do an insert into the new table....
0
Comment
Question by:arhame
[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
  • 3
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
pssandhu earned 2000 total points
ID: 24804619
INSERT INTO LaborReport (LaborId,JobId,EmployeeId,LaborDate,LaborHoursWorked,EmployeeRoleId,TimeTypeId,LaborNotes,LaborPeriodFrom,LaborPeriodTo,CreatedBy,CreatedDt,UpdatedBy,UpdatedDt)
Select LaborId,JobId,EmployeeId,LaborDate,LaborHoursWorked,EmployeeRoleId,TimeTypeId,LaborNotes,LaborPeriodFrom,LaborPeriodTo,CreatedBy,CreatedDt,UpdatedBy,UpdatedDt
From Labor

0
 
LVL 17

Expert Comment

by:pssandhu
ID: 24804626
Oh, by the way I am assuming your column names in the LaborReport table are the same as in Labor table.
Hope that helps.
P.
0
 
LVL 8

Author Comment

by:arhame
ID: 24804661
They are the same, except that LaborReport has it's own UniqueID column, and just stores LaborID (the unique ID on the main table) as an int.  Having the Unique ID's match isn't so important as just having the value there to access if I need it.

Let me log in and try that statement I'll be right back.
0
 
LVL 8

Author Closing Comment

by:arhame
ID: 31601151
Perfect and fast, thanks for your time :)
0
 
LVL 17

Expert Comment

by:pssandhu
ID: 24804711
No problem!
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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