Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ninel
Posting Yak Master
141 Posts |
Posted - 2010-07-07 : 12:26:57
|
My company has a process that runs every 30 minutes or so. This process loads data into the database.I need to write a process that captures cumulative data from a particular column and compares it to the last load.So for example: Load 1, employee 123 had a total of 25 seconds. Load 2 this same employee had a total of 30 seconds.On each load, I need to calculate the difference of the total time for each employee. Load1 25sec, Load2 30sec --> The increment will be 5 sec.I only need to calculate the current load with the last load.Is there any easy way to do this? I'm stumped.Thanks,Ninel |
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2010-07-07 : 12:38:14
|
NinelDo you have a datetime field on your table where you capturing this? Then I guess you can do a SELECT TOP 2 FROM x ORDER BY Loaddatetime ASC<><><><><><><><><><><><><><><><><><><><><><><><><>If you don't have the passion to help people, you have no passion |
 |
|
ninel
Posting Yak Master
141 Posts |
Posted - 2010-07-07 : 12:46:57
|
It's not that simple. There can be multiple records per employee per load. I need to sum them up at each load only and get the difference between this load and last load. |
 |
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2010-07-07 : 12:59:52
|
aha! I thought you would say that since you did not specify that critical piece of information in your first question. So when the load happens you need to do the following two steps1. Grab the last Sum value into variable for current employee in a Load Sum table (which has a datetime field that has default value GETDATE()and probably employeeID field or whatever unique field for employee)2. as you said SUM it up and dump the sum into a LoadSum table for specific employeeid2. next compare last sum dump for employee to current dump<><><><><><><><><><><><><><><><><><><><><><><><><>If you don't have the passion to help people, you have no passion |
 |
|
|
|
|