HiCREATE TABLE #temp(D_A INT, O_B INT , C_C INT, F_D BIT, Value INT ,SUM_D INT) INSERT INTO #temp(D_A ,O_B , C_C , F_D)SELECT 5, 75 ,5 , 0 UNION ALLSELECT 6, 75 ,92 , 0 UNION ALLSELECT 7, 75 ,7 , 0 UNION ALLSELECT 3, 75 ,112, 1 UNION ALLSELECT 6, 75 ,6 , 0 UNION ALLSELECT 3, 75 ,156, 0 UNION ALLSELECT 4, 75 ,4 , 1 UNION ALLSELECT 6, 75 ,376, 0 UNION ALLSELECT 3, 75 ,3 , 0 UNION ALLSELECT 5, 75 ,392, 0 UNION ALLSELECT 6, 75 ,6 , 0 UNION ALLSELECT 3, 75 ,300, 1 SELECT * FROM #tempDROP TABLE #tempHow to split the table data to groups. group Delimiter is 1 in F_D column? The Value formula is ABS(O_B - C_C) for all rows in all groups.? Find MIN valus formula is MIN(VALUE) in each group.? After find the minimum value for each group. ? Take the minimum value row in Value column and sum of current row D_A value + previous D_A rows values.these value should be in min value row calci..The groups and calculation are should be...like this.............D_A O_B C_C F_D Value SUM_D5 75 5 0 70 6 75 100 0 25 SUM(D_A)=11 11 7 75 8 0 67 3 75 25 1 50 MIN(VALUE)=25 6 75 6 0 69 SUM(D_A)=6 63 75 156 0 81 4 75 4 1 71 MIN(VALUE)=696 75 376 0 301 3 75 3 0 72 5 75 392 0 317 6 75 6 0 69 SUM(D_A)=20 20 3 75 300 1 225 MIN(VALUE)=69 Please help on this thanks in advance........