Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends

I have two tables 1) Leavesperyear
Columns:
LeaveId LeaveCount
1 12
2 12
..............etc. 6 types of leaves
2) EmployerMaster
Columns:
Empid Empname
1 Rama
2 Devi

I have third table : EmployeeLeavesList
Columns:
Empid LeaveId Noofleaves
1 1 12
1. 2. 12
...up to 6 leaves
2 1. 12
2. 2. 12
..like this data should be inserted into third table for all employees.The noofleaves should be come from first table.
If Employee gender is male leaveid 6 should not assign to that employee for female it should be assign.

Based on this conditions how to achieve this by sqlquery???

What I have tried:

I tried with joins and insert statement with select query
Posted
Updated 29-Nov-16 2:17am
Comments
Tomas Takac 28-Nov-16 10:16am    
In the first table you have leaves aggregated for all employees. There is no way you can break it back to employee level, not without more information anyway. I would suggest you store data as in EmployeeLeavesList then you can easily generate Leavesperyear from that.

EmployerMaster table should have a relation to Leavesperyear table. There should be a foreign key on the EmployerMaster table. If these table are the master tables, then there should be a transaction table. Transaction table is where the INPUTS of employee and their leaves should be stored.
 
Share this answer
 
SQL
SELECT	A.Col1, A.Col2, B.Col1, B.Col2
INTO	Table3
FROM	Table1 A
INNER JOIN      Table2 B ON A.Col1 = B.Col1
 
Share this answer
 
Hi Please Add colunm Empid in Leavesperyear table and after run below query

SQL
insert into EmployeeLeavesList
select em.Empid,LeaveId,LeaveCount from Leavesperyear as le , EmployerMaster as em
where le.Empid=em.Empid 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900