Hello All - so I have a History Log that logs when something is Checked In and Checked Out. I need to create a query that will tell me the typical duration something is checked out.
So step 1 is to some how pair together a Checked OUT status with a Checked IN status. If there is no Checked IN status the I will replace it with GetDate().
The date looks like so:
What i was thinking was something along these lines:
- Get ALL the "OUT"'s then look for the closest "IN" with the same DEVICE_ID that is Greater than the OUT I just grabbed.
ex. Using the Example above we would grab D0003 with the time of 2011-07-11 10:50:25.140 and then look for the MIN "IN" for D0003 that is Greater than "2011-07-11 10:50:25.140" which would be "2011-07-11 10:50:30.780" and it would return a duration of 5 seconds.
So in the case of D0001 there is no "IN" so I would just replace it with GETDATE() so the duration would grow every time you run the query.
- Sounds simple enough... but obviously not. I think I have the logic there just don't know where to begin with the SQL.
Any ideas? OR better logic to start with?
- Matt
"If I must boast, I will boast of the things that show my weakness"
- Windows 2003 Server, 98 SE, XP
- VB.NET, VSTS 2010, ASP.NET, EXCEL VBA, ACCESS, SQL 2008
So step 1 is to some how pair together a Checked OUT status with a Checked IN status. If there is no Checked IN status the I will replace it with GetDate().
The date looks like so:
Code:
ID USER_ID DEVICE_ID ACTION DATE_TIME
92 U004 D0001 OUT 2011-07-11 10:50:17.903
93 U004 D0002 IN 2011-07-11 10:50:21.607
94 U004 D0003 OUT 2011-07-11 10:50:25.140
95 U004 D0003 IN 2011-07-11 10:50:30.780
What i was thinking was something along these lines:
- Get ALL the "OUT"'s then look for the closest "IN" with the same DEVICE_ID that is Greater than the OUT I just grabbed.
ex. Using the Example above we would grab D0003 with the time of 2011-07-11 10:50:25.140 and then look for the MIN "IN" for D0003 that is Greater than "2011-07-11 10:50:25.140" which would be "2011-07-11 10:50:30.780" and it would return a duration of 5 seconds.
So in the case of D0001 there is no "IN" so I would just replace it with GETDATE() so the duration would grow every time you run the query.
- Sounds simple enough... but obviously not. I think I have the logic there just don't know where to begin with the SQL.
Any ideas? OR better logic to start with?
- Matt
"If I must boast, I will boast of the things that show my weakness"
- Windows 2003 Server, 98 SE, XP
- VB.NET, VSTS 2010, ASP.NET, EXCEL VBA, ACCESS, SQL 2008