How about a case statement to catch if it is a negative value and then calculate properly:
CASE WHEN DATEDIFF(HOUR, FromTime, ToTime) < 0
THEN 24 - DATEPART(hour, FromTime) + DATEPART(hour, ToTime)
ELSE DATEDIFF(HOUR, FromTime, ToTime)
END AS TotalHours
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…