;with cte as
(
select FingerId, [Date],
LogTime,
row_number() over(partition by FingerId order by LogTime) as rn
from InOut
)
select C3.EmployeeName,C1.FingerId,
C1.LogTime as InTime,
C2.LogTime as OutTime,
C2.[Date]
from cte as C1
left outer join cte as C2
on C1.FingerId = C2.FingerId and
C1.rn + 1 = C2.rn INNER JOIN
EmployeeMaster as C3 ON C3.Fingerid = C2.Fingerid
where C1.rn % 2 = 1 and C3.EmployeeName = 'xyz' and C1.[Date] between '2011-07-21' and '2011-07-29' order by C2.[Date]
select * From Inout order by LogTime asc
I am having INOUT Table It have 5 record and 3 record is of 2011-07-2011
InOuT Table:
AutoId FingerId LogTime Date
1 22 11:18:48 AM 2011-07-29
2 22 11:19:54 AM 2011-07-29
3 22 11:20:50 AM 2011-07-21
4 22 11:21:54 AM 2011-07-21
5 22 11:21:59 AM 2011-07-21
I am getting this output by this above query
EmployeeName FingerId InTime OutTime Date
xyz 22 11:20:50 AM 11:21:54 AM 2011-07-21
xyz 22 11:18:48 AM 11:19:54 AM 2011-07-29
I Want this type of OutPut:-
EmployeeName FingerId InTime OutTime Date
xyz 22 11:20:50 AM 11:21:54 AM 2011-07-21
xyz 22 11:21:59 AM ---- 2011-07-21
xyz 22 11:18:48 AM 11:19:54 AM 2011-07-29
Here 2nd row is having InTime and i want outtime should display “—” dash.But i m not getting with this query. Query is correct but need to do modify for this.
I’ve made some modifications to your query which I’m posting now with the changes highlighted in bold:
Originally I was thinking about changing
C1.[Date]in the SELECT clause toC2.[Date], but then I wasn’t sure it would be quite adequate a replacement in case the two dates were different. You can see for yourself which option is better, if any.