Solved

Copying Data from one table to another Sql Server 2005

Posted on 2009-07-08
5
191 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 500 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

734 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