My table structure is like \[code\]CardNumber DateTime 1 2013-03-14 09:40:28.0001 2013-03-14 12:45:38.0001 2013-03-14 21:40:20.0002 2013-03-14 21:40:12.0002 2013-03-14 23:23:28.0002 2013-03-15 00:45:28.0002 2013-03-15 07:12:28.000\[/code\]now I want for every card for every day \[code\]In Time\[/code\] and \[code\]Out Time\[/code\]. And I have written a query which gives result for day shift but for the night shift it gives wrong time. my query is\[code\]SELECT CardholderEvent.CardNumber, FirstDay.MinEntry, FirstDay.MaxEntryFROM CardholderEventINNER JOIN (SELECT CardholderEvent.CardNumber, MIN(CardholderEvent.DateTime) AS MinEntry, MAX(CardholderEvent.DateTime) as MaxEntry FROM CardholderEvent GROUP BY CardholderEvent.CardNumber, CAST(DateTime as DATE)) FirstDayON (FirstDay.MinEntry) = CardholderEvent.DateTimeWHERE DateTime BETWEEN '3/1/2013 12:00:00 AM' AND '4/1/2013 12:00:00 AM'ORDER BY FirstDay.MinEntry, CardholderEvent.CardNumber;Result10040 2013-03-14 09:40:28.000 2013-03-14 21:28:59.00010022 2013-03-14 09:46:44.000 2013-03-14 19:47:34.00010020 2013-03-14 10:09:11.000 2013-03-14 16:14:11.000 10037 2013-03-16 21:28:22.000 2013-03-16 21:29:44.000\[/code\]I want result like\[code\]cardnumber InTime OutTime1 2013-03-14 09:40:28.000 2013-03-14 21:40:20.0002 2013-03-14 21:40:12.000 2013-03-15 07:12:28.000\[/code\]Please any body can help me for this??? Thanks in advance...