WITH t AS ( SELECT 1 templatprocno, 1 proctypeprocno, 'a' procname, 8.00 stdworktime UNION ALL SELECT 1, 2, 'b', 6.00 UNION ALL SELECT 1, 3, 'c', 2.00 UNION ALL SELECT 1, 4, 'd', 8.00 UNION ALL SELECT 1, 5, 'e', 10.00 UNION ALL SELECT 2, 1, 'f', 4.00 UNION ALL SELECT 2, 2, 'g', 6.00 UNION ALL SELECT 2, 3, 'h', 4.00 UNION ALL SELECT 2, 4, 'i', 4.00 UNION ALL SELECT 3, 1, 'j', 4.00 UNION ALL SELECT 3, 2, 'k', 8.00 UNION ALL SELECT 3, 3, 'l', 3.00 UNION ALL SELECT 4, 1, 'm', 2.00 UNION ALL SELECT 4, 2, 'n', 3.00 UNION ALL SELECT 4, 3, 'o', 3.00 UNION ALL SELECT 4, 4, 'p', 4.00 ) SELECT templatprocno, proctypeprocno, procname, stdworktime , FORMAT(DATEADD(DAY, (tm - stdworktime) / 8, dt), 'yyyyMMdd') sdt , FORMAT(DATEADD(DAY, (tm - 1 ) / 8, dt), 'yyyyMMdd') edt FROM (SELECT templatprocno, proctypeprocno, procname, stdworktime , FORMAT(GETDATE(), 'yyyyMMdd') dt , SUM(stdworktime) OVER(ORDER BY templatprocno, proctypeprocno) tm FROM t ) a ;