0

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.

Learner
  • 776
  • 6
  • 14
  • 40

1 Answers1

0

I Reversed the condition and it worked, thanks, following is the sql

ROUND(SUM(DATEDIFF(SECOND, LogInTime, 
                    IIF(LogOffTime IS NULL,GetDate(),LogOffTime)
                    )) / 3600.0, 1) as SystemHours
Learner
  • 776
  • 6
  • 14
  • 40