I am using following sql to calculate time difference for records in a table and taking sum of them grouping by employeeId and login Date, But I am injecting a condition in the middle,If the LogOffTime is null I want to take the difference of current time of the day and the time employee loggedin. Note : Each employee can have multiple Logins and LogOffs in a day
ROUND(SUM(DATEDIFF(SECOND, LogInTime, IIF(LogOffTime <> NULL,LogOffTime,GetDate()))) / 3600.0, 1) as HoursWorked
But my condition
IIF(LogOffTime <> NULL,LogOffTime,GetDate()) seems incorrect here, Does somebody has any Idea, if the condition is correct.