AmitavaCh
asked on
Joining Statement in SQL
Hi,
The following statement generates output of attendance records (from Honeywell based access control system) and Lotus Notes based workflow application pulled the information to publish the records.
SELECT * FROM
(SELECT a.link3,
REPLACE (CONVERT(VARCHAR(11),TIMES TAMP, 106),' ', '-') new_date,
MIN(a.TIMESTAMP) AS First_in,
MAX(a.TIMESTAMP) AS Last_Out
from History a
where REPLACE (CONVERT(VARCHAR(11),TIMES TAMP, 106),' ', '-') = '29-apr-2014'
GROUP BY a.link3, REPLACE (CONVERT(VARCHAR(11),TIMES TAMP, 106),' ', '-')
) A
INNER JOIN emp_sms_email b ON a.link3 = b.CardHolderID
where b.CardNumber = '1'
Recently, we have implemented Biometrics equipments at various locations and IN/OUT of an employee is getting stored in a separate Table namely "Timewatch_attendance", which has the following four fields:
LastDate,
FirstIN,
LastOut,
EmpID : EmpID is unique in both the case
Now, I am facing challenges in joining these two to generate a single output file, which I can finally display through Lotus Notes application.
The query should check and display First_IN & FirstIn (MIN) and Last_Out and LastOut (Max) in both the table/view and generate the output accordingly.
Can you help me please.
Regards,
The following statement generates output of attendance records (from Honeywell based access control system) and Lotus Notes based workflow application pulled the information to publish the records.
SELECT * FROM
(SELECT a.link3,
REPLACE (CONVERT(VARCHAR(11),TIMES
MIN(a.TIMESTAMP) AS First_in,
MAX(a.TIMESTAMP) AS Last_Out
from History a
where REPLACE (CONVERT(VARCHAR(11),TIMES
GROUP BY a.link3, REPLACE (CONVERT(VARCHAR(11),TIMES
) A
INNER JOIN emp_sms_email b ON a.link3 = b.CardHolderID
where b.CardNumber = '1'
Recently, we have implemented Biometrics equipments at various locations and IN/OUT of an employee is getting stored in a separate Table namely "Timewatch_attendance", which has the following four fields:
LastDate,
FirstIN,
LastOut,
EmpID : EmpID is unique in both the case
Now, I am facing challenges in joining these two to generate a single output file, which I can finally display through Lotus Notes application.
The query should check and display First_IN & FirstIn (MIN) and Last_Out and LastOut (Max) in both the table/view and generate the output accordingly.
Can you help me please.
Regards,
ASKER
Field 'EmpID' exists in both the table.
Since EmpID is common, query to check whether the person marked his presence at Office location or site location, similarly while leaving.
E.g. Today, I come to office and marked my presence through HID Based Card in the morning at 9:45 a.m. and left at 12:30 for our site. At 1:30 I swiped my finger at Biometric machines and finally at 7:00 p.m. and left from there, next day my FirstIN will be 9:45 a.m. and lastOut will be at 7:00 p.m. (which is currently stored in Timewatch_attendance table).
Thank you
Since EmpID is common, query to check whether the person marked his presence at Office location or site location, similarly while leaving.
E.g. Today, I come to office and marked my presence through HID Based Card in the morning at 9:45 a.m. and left at 12:30 for our site. At 1:30 I swiped my finger at Biometric machines and finally at 7:00 p.m. and left from there, next day my FirstIN will be 9:45 a.m. and lastOut will be at 7:00 p.m. (which is currently stored in Timewatch_attendance table).
Thank you
Provide some sample data and expected result.
What is your SQL Server version?
What is your SQL Server version?
ASKER
Hi,
Enclosed please find the sample data and expected result.
I am using SQL Server 2005 STD.
Thank you,
EE-Solution.pptx
EE-Solution.xlsx
Enclosed please find the sample data and expected result.
I am using SQL Server 2005 STD.
Thank you,
EE-Solution.pptx
EE-Solution.xlsx
ASKER
Hi Hengel,
Yes, Full Outer Join is required - I also need to extract Min & Max time once again to get the desired result.
SELECT * FROM
(SELECT a.link3,
REPLACE (CONVERT(VARCHAR(11),TIMES TAMP, 106),' ', '-') new_date,
MIN(a.TIMESTAMP) AS First_in,
MAX(a.TIMESTAMP) AS Last_Out
from History a
where REPLACE (CONVERT(VARCHAR(11),TIMES TAMP, 106),' ', '-') = '29-apr-2014'
GROUP BY a.link3, REPLACE (CONVERT(VARCHAR(11),TIMES TAMP, 106),' ', '-')
) A
INNER JOIN emp_sms_email b ON a.link3 = b.CardHolderID
FULL OUTER JOIN TimeWatch_Attendance ON b.EmpID=TimeWatch_Attendan ce.Emp_Cod e
where b.CardNumber = '1';
The above query is giving me all the entries (dates) of Biometrics for Card # '1', however, I need the record only for 29-apr-2014 i.e. today-1
Yes, Full Outer Join is required - I also need to extract Min & Max time once again to get the desired result.
SELECT * FROM
(SELECT a.link3,
REPLACE (CONVERT(VARCHAR(11),TIMES
MIN(a.TIMESTAMP) AS First_in,
MAX(a.TIMESTAMP) AS Last_Out
from History a
where REPLACE (CONVERT(VARCHAR(11),TIMES
GROUP BY a.link3, REPLACE (CONVERT(VARCHAR(11),TIMES
) A
INNER JOIN emp_sms_email b ON a.link3 = b.CardHolderID
FULL OUTER JOIN TimeWatch_Attendance ON b.EmpID=TimeWatch_Attendan
where b.CardNumber = '1';
The above query is giving me all the entries (dates) of Biometrics for Card # '1', however, I need the record only for 29-apr-2014 i.e. today-1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you eventually may need a FULL OUTER JOIN...
Open in new window