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 |
|
jj7353
Starting Member
10 Posts |
Posted - 2006-07-18 : 09:10:31
|
| Hi, I need some help figuring out a way to find the difference between two or more different records.Let me try to explain by using some sample data.1 zzz 07/01/2006 245 10 24.5 01 zzz 07/02/2006 220.5 15 12.25 51 zzz 07/03/2006 208.25 17 41.65 21 zzz 07/04/2006 203.35 100 166.6 83Now, I have the data for columns 1 through 5 which are:task_id,person_alias,date_task_completed,estimate_time_to_complete_task,percentage_of_task_completedactual_completed_time,diff_percentage_from_last_requestThe last two columns are what I am trying to figure out how to derive. The way the others work is the 245 is a Given amount estimated time we think it will take to finish task 1. Each time they do some work, for task 1, they estimate how much of the total task completed and do so by posting a percentgage completed and continue to do that daily until they completed it 100%. Between the days I need to determine the actual time they have taken and the difference in percentages.Hope that makes sense.ThanksJohnJohn |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-07-18 : 09:43:43
|
[code]declare @table table( task_id int, person_alias varchar(10), date_task_completed datetime, estimate_time_to_complete_task int, percentage_of_task_completed decimal(10,2))insert into @tableselect 1 , 'zzz', '07/01/2006', 245, 10 union allselect 1 , 'zzz', '07/02/2006', 220.5, 15 union allselect 1 , 'zzz', '07/03/2006', 208.25, 17 union allselect 1 , 'zzz', '07/04/2006', 203.35, 100select *, actual_completed_time = percentage_of_task_completed * estimate_time_to_complete_task / 100, diff_percentage_from_last_request = percentage_of_task_completed - isnull((select top 1 percentage_of_task_completed from @table x where x.task_id = t.task_id and x.date_task_completed < t.date_task_completed order by x.date_task_completed desc), percentage_of_task_completed)from @table torder by date_task_completed/* RESULT task_id person_alias date_task_completed estimate_time_to_complete_task percentage_of_task_completed actual_completed_time diff_percentage_from_last_request ----------- ------------ ------------------------------------------------------ ------------------------------ ---------------------------- --------------------------- --------------------------------- 1 zzz 2006-07-01 00:00:00.000 245 10.00 24.500000 .001 zzz 2006-07-02 00:00:00.000 220 15.00 33.000000 5.001 zzz 2006-07-03 00:00:00.000 208 17.00 35.360000 2.001 zzz 2006-07-04 00:00:00.000 203 100.00 203.000000 83.00(4 row(s) affected)*/[/code] KH |
 |
|
|
jj7353
Starting Member
10 Posts |
Posted - 2006-07-18 : 15:11:04
|
| KH - thank you so much for your help. I believe that is exactly what I need - your a life saver.JohnJohn |
 |
|
|
|
|
|
|
|