27
Views
3
Comments
Solved
sql

How to add total attendance hours as in the picture

sql.PNG
2018-10-29 08-31-03
João Marques
 
MVP
Solution

Hi Andrew,


You want to update the field TotalAttendanceOfHours with the number of hours between logout (as an input) and login for the records with no logout date time, is that it?

If that is the case, consider the following SQL:


Update {Attendance}

Set {Attendance}.[LogoutDateTime] = @logoutDateTime,
{Attendance}.[TotalAttendanceOfHours] = DATEDIFF(hh, {Attendance}.[LoginDateTime], @logoutDateTime)

Where {Attendance}.[UserId]=@UserId
/* if you want to update only the login record with no logout date */
and {Attendance}.[LogoutDateTime] = @NullDate


If you want to update only the login record with no logout date, add the last AND clause and the parameter NullDate with the NullDate() value.

If you want to fill the difference from hours to seconds, for example, you can just change the hh to ss (more information on DATEDIFF datepart parameters here) but I would advise changing the number of the attribute TotalAttendanceOfHours to TotalAttendanceOfSeconds to avoid confusion.

Hope it helps.


Regards,
João

2021-01-05 18-22-18
andrew mahfouz

in my case i need to update Logout Date Time (as an input and cast with login date time in the same date)

and then  update total attendance(with login date time and logout date time as input)

UserImage.jpg
Shilpa Uppund

hi Andrew,

Didn't exactly get as to what you want to do. From the attached file, you are trying to update the LogoutDateTime and TotalAttendanceofHours based on login time being same as logout time and the TotalAttendanceofHours in secs? But how can login time be same as logout time?

Regards,

Shilpa

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.