I would make your final choice as follows:
SELECT EmplID , EmplName , InTime , [TimeOut] , [DateVisited] , CONVERT(varchar(3),DATEDIFF(minute,InTime, TimeOut)/60) + ':' + RIGHT('0' + CONVERT(varchar(2),DATEDIFF(minute,InTime,TimeOut)%60),2) as TotalHours from times Order By EmplID, DateVisited
Any solution trying to use DATEDIFF(hour,... should be complicated (if it is correct), because DATEDIFF counts the transitions - DATEDIFF(hour,...09:59',...10:01') will return 1 due to the transition of hours from 9 to 10. So I'm just using DATEDIFF in minutes.
The foregoing may still be inaccurate if seconds are involved (it may overestimate a bit since its counting minutes pass), so if you need second or millisecond precision, you need to configure DATEDIFF to use these units, and then apply the appropriate constant separation ( according to the clock above) to simply return the hours and minutes.
Damien_The_Unbeliever
source share