-2

I have table with columns and data as well

Id    CardNo    IODate                     IOStatus
====  ========  =========================  ========
1     0004      2011-02-17 10:48:39.000    Entry    
2     0004      2011-02-17 10:55:39.000    Exit    
3     0004      2011-02-17 11:48:39.000    Entry
4     0004      2011-02-17 15:55:39.000    Exit

I want to get the hours and minutes spent between entry and exit. If the entry is in one date and exit is in the next day it should able to calculate the hours. All this has to be done in sql server.

Mike Guthrie
  • 4,029
  • 2
  • 25
  • 48

1 Answers1

0

You want to do that in SQL? Try this: Suppose the name is of the table is Table:

Select DATEDIFF(hour,t1.IODate,t2.IODate) from Table t1 left join t2 on t1.ID=t2.ID-1 
Kent Lee
  • 107
  • 4
  • 13