Solved

Copying Data from one table to another Sql Server 2005

Posted on 2009-07-08
5
183 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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