Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a table called Attendance


Atn_No int
Atn_Date date
Atn_EmpNo varchar


I have another table Called Operation

Opn_No int
OPn_StartDate date
Opn_EndDate date
Opn_Activity varchar
Opn_ActivityHour int

What i want to check with Operation with the help Start & End Date Who's employees was working on that operation

Below is Operation Table DATA

Opn_StartDate      Opn_EndDate           Opn_Activity         Opn_ActivityHour
01-01-2016         03-01-2016            ABC                      1
04-01-2016         06-01-2016            XYZ                      2
07-01-2016         08-01-2016            lmn                      4




Below Attendance Table DATA


Atn_No            Atn_Date           Atn_EmpNo
Atn-1             02-01-2016          A-1
Atn-2             02-01-2016          A-2
Atn_3             05-01-2016          A-3



Thanks
Basit.

What I have tried:

What i was thinking create a temporay table first save all the operation records with temporay table and with the help of while loop add check the attendance if the attendance in between start and enddate save that records. but im looking for sql query if easiy then no need to create this method.
Posted
Updated 31-Aug-16 10:00am
v2

Assuming you do not have two operations with overlapping dates, try this:

Select * 
 from operation o
 left outer join Attendance a on a.atn_date >= o.opn_startdate and a.atn_date <= o.opn_enddate



If you have overlapping operations, then you'll need to put SOMETHING in your database to link the two records.
 
Share this answer
 
Comments
Maciej Los 31-Aug-16 16:00pm    
5ed!
 
Share this answer
 
table 1

Opn_StartDate Opn_EndDate Opn_Activity Opn_ActivityHour Atn_EmpNo(foreign key)

table 2

Atn_No Atn_Date Atn_EmpNo(primary key)




now just use join and you will get your answer.
 
Share this answer
 
Comments
basitsar 31-Aug-16 6:35am    
Dear, there is no relation between thoes table only need to check start & endDate with operation table and check attendance table if employee is in between start & endDate then show this table.

Thanks
Basit.

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