immad
Programmer
- May 31, 2013
- 7
my data is like this
eid-----------date------------------------------time--------------------------status
26359---2013-01-01 13:00:00.000------2013-01-01 09:50:00.000--------IN
26359---2013-01-01 13:00:00.000------2013-01-01 11:47:00.000--------OUT
26359---2013-01-01 13:00:00.000------2013-01-01 17:21:00.000--------IN
26359---2013-01-01 13:00:00.000------2013-01-01 18:40:00.000--------OUT
26359---2013-01-02 13:00:00.000------2013-01-02 09:00:00.000--------IN
26359---2013-01-02 13:00:00.000------2013-01-02 18:00:00.000--------OUT
i am using this query
SELECT a.eid, a.date, d.InTime, e.OutTime
FROM
(SELECT DISTINCT date, eid FROM #TestTb) a
OUTER APPLY (SELECT b.eid, b.Date, MIN(b.Time) InTime FROM #TestTb b WHERE a.eid = b.eid AND a.date = b.date GROUP BY b.eid, b.Date) d
OUTER APPLY (SELECT c.eid, c.Date, MAX(c.Time) OutTime FROM #TestTb c WHERE a.eid = c.eid AND a.date = c.date GROUP BY c.eid, c.Date) e
it gives me that result
eid------------------date-----------------------timein-----------------------timeout
26359--------2013-01-01 13:00:00.000---2013-01-01 09:50:00.000--2013-01-01 18:40:00.000
i want this type of result
eid------------------date--------------------timein------------------------------timeout
26359--------2013-01-01 13:00:00.000---2013-01-01 09:50:00.000--2013-01-01 11:47:00.000
26359--------2013-01-01 13:00:00.000---2013-01-01 17:21:00.000--2013-01-01 18:40:00.000
please help me out
thanks in advance
eid-----------date------------------------------time--------------------------status
26359---2013-01-01 13:00:00.000------2013-01-01 09:50:00.000--------IN
26359---2013-01-01 13:00:00.000------2013-01-01 11:47:00.000--------OUT
26359---2013-01-01 13:00:00.000------2013-01-01 17:21:00.000--------IN
26359---2013-01-01 13:00:00.000------2013-01-01 18:40:00.000--------OUT
26359---2013-01-02 13:00:00.000------2013-01-02 09:00:00.000--------IN
26359---2013-01-02 13:00:00.000------2013-01-02 18:00:00.000--------OUT
i am using this query
SELECT a.eid, a.date, d.InTime, e.OutTime
FROM
(SELECT DISTINCT date, eid FROM #TestTb) a
OUTER APPLY (SELECT b.eid, b.Date, MIN(b.Time) InTime FROM #TestTb b WHERE a.eid = b.eid AND a.date = b.date GROUP BY b.eid, b.Date) d
OUTER APPLY (SELECT c.eid, c.Date, MAX(c.Time) OutTime FROM #TestTb c WHERE a.eid = c.eid AND a.date = c.date GROUP BY c.eid, c.Date) e
it gives me that result
eid------------------date-----------------------timein-----------------------timeout
26359--------2013-01-01 13:00:00.000---2013-01-01 09:50:00.000--2013-01-01 18:40:00.000
i want this type of result
eid------------------date--------------------timein------------------------------timeout
26359--------2013-01-01 13:00:00.000---2013-01-01 09:50:00.000--2013-01-01 11:47:00.000
26359--------2013-01-01 13:00:00.000---2013-01-01 17:21:00.000--2013-01-01 18:40:00.000
please help me out
thanks in advance