Solved

add data from two tables into one table

Posted on 2013-01-01
4
449 Views
Last Modified: 2013-01-02
I have a table called employees: within it I have various fields two of which being:

emp_uid, and emp_shift_duration.

emp_uid is unique.

emp_shift_duration varies a bit becasue most emps work either 4 hours, 5 hours, 6 hours or 8 hours.

Sometimes people are out and I want to use their hours to do special projects so I want to keep tabs on when they miss hours. The shift sup. can keep track of this but in order to save time I only want him to 'edit' the missing hours when needed, not add hours eveyday so I want the table populated ahead of time.

so I created another table which is called :

emp_hours_worked: fields are 3 : emp_uid, projected_hours,and date.

I wish to populate emp_hours_worked with employee data from employees table.
emp_uid, and emp_shift_duration; and also populate date with the days of the year for 'each' employee: this will be a very long table because the result will be that each employee will have a record for each date of the year.: therefore using a simple php script the sup. can go in and edit any necessary dates and then I will run a query to sum up the hours for the current pay weeks.

emp_hours_worked will look something like this.

emp_uid,projected_hours,date

3432,4,01-01-2013
3432,4,01-02-2013
3432,4,01-03-2013...etc.

7715,8,01-01-2013
7715,8,01-02-2013...etc...  or ....

3432,4,01-01-2013
7715,8,01-01-2013
9824,5,01-01-2013
9954,8.01-01-2013... etc. depending how its shown but did this to get the idea through.

So I am looking for sql statement to 'insert' all this data into the emp_hours_worked table.

Well anyways this is my idea any better solutions would be welcome.
0
Comment
Question by:opelraja
  • 2
4 Comments
 
LVL 21

Accepted Solution

by:
oleggold earned 250 total points
ID: 38735111
insert into emp_hours_worked
(select emp_uid, to_date(emp_shift_duration,'hh:mi:ss'),trunc(emp_shift_duration) from employees e)
0
 
LVL 21

Expert Comment

by:oleggold
ID: 38735116
I don't see any other table for the select's join condition,in case it's there use
'employees e left join <other tab t> on field'
0
 

Author Comment

by:opelraja
ID: 38735243
I figured it out like this:

I created a table 'dates with just '_dates' as a field : being the whole year day to day of 2013.

then I used this query:

Insert into emp_hours_worked(emp_uid,projected_hours,_date)
SELECT emp_uid, emp_shift_duration,_date
FROM employees_table AS a, date AS b;

So it populated a line for each employee for each day. Now I just need a faster laptop for this huge table.
0
 
LVL 9

Assisted Solution

by:keyu
keyu earned 250 total points
ID: 38735653
if everytime you are creating new table then go for this...

SELECT emp_uid, emp_shift_duration as projected_hours,_date into emp_hours_worked FROM employees_table AS a, date AS b

if you already have table and wants to make entries than go for this as mentioned by you in your previous comment....

Insert into emp_hours_worked(emp_uid,projected_hours,_date)
SELECT emp_uid, emp_shift_duration,_date
FROM employees_table AS a, date AS b;
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

23 Experts available now in Live!

Get 1:1 Help Now