Q:

How to Get CheckIn-CheckOut time Difference from Punch Machine Attendance Log with Single Row using SQL Query?

we are using Punch Machine for Attendance with zkemkeeper.dll and geting AttLog using Vs.net 2010.How can Get Records from SQL Query? 
my table structure like this 
LogID       int P.K.
DeviceIP    varchar
EnrollNo    int
AttDate     datetime
AttYear     int 
AttMonth    int
AttDay      int
AttTime     varchar

My current output:
LogID   EnrollNo     AttDate    AttYear AttMonth  AttDay  AttTime

1   319 1/9/2011 9:55:00 PM 2011    8    31 9:55    

2   319 1/9/2011 18:30:00 PM    2011    8    31 18:30   

3   325 1/9/2011 10:00:00 PM    2011    8    31 10:00   

4   325 1/9/2011 18:35:00 PM    2011    8    31 18:35   

I want the new output like this with calculation of in-out time difference:
LogID  EnrollNo   AttDate          AttYear  AttMonth    AttDay  In    out    Diff

1   319 1/9/2011 9:55:00 PM 2011   8         31         9:55   18:30     8:35

2   325 1/9/2011 6:30:00 PM 2011   8         31         10:00   18:35    8:35

A:

declare @t table (EnrollNo int, [Date] datetime, Time varchar(5))
insert @t select 1, '8-10-2011 12:00:32', '13:12' 
union all select 1, '8-10-2011 12:00:32', '23:14' 
union all select 2, '8-10-2011 12:00:32', '11:12' 
union all select 2, '8-10-2011 12:00:32', '20:14' 
union all select 3, '8-10-2011 12:00:35', '12:12' 
union all select 3, '8-10-2011 12:00:32', '23:14' 
union all select 4, '8-10-2011 12:00:32', '17:12' 
union all select 4, '8-10-2011 12:00:32', '23:14'

select 
  EnrollNo, 
  CAST(CONVERT(varchar, Date, 101) AS DateTime), 
  right('0' + cast(datediff(hour, cast(min(Time) as datetime), 
  cast(max(Time) as datetime)) as varchar(2)),2) + ':' + 
    right('0' + cast(datediff(minute, cast(min(Time) as datetime), 
    cast(max(Time) as datetime)) % 60 as varchar(2)),2),
  min(Time),
  max(Time)
from @t group by EnrollNo,CAST(CONVERT(varchar, Date, 101) AS DateTime)

