I'm running SQL Server 2005 and have the following question.
I have a table which tracks the events created by a group of users.
ID code tstamp username
574015 1 4/8/08 08:14:26 user1
575349 2 4/8/08 09:47:40 user1
575352 1 4/8/08 09:53:14 user1
579345 2 4/8/08 14:19:24 user1
579406 1 4/8/08 14:20:38 user1
583487 2 4/8/08 16:37:34 user1
592824 1 4/9/08 08:28:38 user2
600609 2 4/9/08 16:44:02 user2
593334 1 4/9/08 08:59:17 user3
594703 2 4/9/08 09:29:50 user3
594715 1 4/9/08 09:30:03 user3
600606 2 4/9/08 16:43:56 user3
code 1 = log on, code 2 = logoff. There are other codes in the table but they aren't needed so the IDs will not be sequential. I need to find the total time the user was logged into the system for each day. The user can log in and out of the system multiple times a day. So the sum of all the log in times.
The end result I was looking for was something like the example below which has the log on times for each person which would be stored in a permanent table for easier reporting.
username logontime logofftime signon day
user1 4/8/08 08:14:26 4/8/08 09:47:40 1:33 4/8/2008
user1 4/8/08 09:53:14 4/8/08 14:19:24 4:26 4/8/2008
user1 4/8/08 14:20:38 4/8/08 16:37:34 2:16 4/8/2008
user3 4/9/08 08:59:17 4/9/08 09:29:50 0:30 4/9/2008
user3 4/9/08 09:30:03 4/9/08 16:43:56 7:13 4/9/2008
user2 4/9/08 08:28:38 4/9/08 16:44:02 8:15 4/9/2008
What I have started with is I created a table which is populated daily with the log on and log off times (only codes 1 and 2) of the previous day using a SSIS package, but from there I am unsure of how to continue and get the difference in times for time each user logs on and off when I don't know what the next record for that user would be.
Thank you!!!
I have a table which tracks the events created by a group of users.
ID code tstamp username
574015 1 4/8/08 08:14:26 user1
575349 2 4/8/08 09:47:40 user1
575352 1 4/8/08 09:53:14 user1
579345 2 4/8/08 14:19:24 user1
579406 1 4/8/08 14:20:38 user1
583487 2 4/8/08 16:37:34 user1
592824 1 4/9/08 08:28:38 user2
600609 2 4/9/08 16:44:02 user2
593334 1 4/9/08 08:59:17 user3
594703 2 4/9/08 09:29:50 user3
594715 1 4/9/08 09:30:03 user3
600606 2 4/9/08 16:43:56 user3
code 1 = log on, code 2 = logoff. There are other codes in the table but they aren't needed so the IDs will not be sequential. I need to find the total time the user was logged into the system for each day. The user can log in and out of the system multiple times a day. So the sum of all the log in times.
The end result I was looking for was something like the example below which has the log on times for each person which would be stored in a permanent table for easier reporting.
username logontime logofftime signon day
user1 4/8/08 08:14:26 4/8/08 09:47:40 1:33 4/8/2008
user1 4/8/08 09:53:14 4/8/08 14:19:24 4:26 4/8/2008
user1 4/8/08 14:20:38 4/8/08 16:37:34 2:16 4/8/2008
user3 4/9/08 08:59:17 4/9/08 09:29:50 0:30 4/9/2008
user3 4/9/08 09:30:03 4/9/08 16:43:56 7:13 4/9/2008
user2 4/9/08 08:28:38 4/9/08 16:44:02 8:15 4/9/2008
What I have started with is I created a table which is populated daily with the log on and log off times (only codes 1 and 2) of the previous day using a SSIS package, but from there I am unsure of how to continue and get the difference in times for time each user logs on and off when I don't know what the next record for that user would be.
Thank you!!!