Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

tSQL Recursive SUM

$
0
0

Hello,

What I want happen is to add each number in the EmployeeCount column, order by date, until the sum is =>24.  If the condition is met return the date when it goes over 24.  How can I achieve this?

For example, 6+7+8+7= 28, so 2012-05-09 00:00:00 would be the first answer I’m looking for.  But I want it to continue to do this to the rest of the set, so the next iteration would start at 2012-05-09 00:00:00 until the same condition is met again.

Any suggestions is appreciated

DimDate                                     EmployeeCount
2012-05-06 00:00:00                6
2012-05-07 00:00:00                7
2012-05-08 00:00:00                8
2012-05-09 00:00:00                7
2012-05-10 00:00:00                8
2012-05-11 00:00:00                9
2012-05-12 00:00:00                6
2012-05-13 00:00:00                6
2012-05-14 00:00:00                7
2012-05-15 00:00:00                7
2012-05-16 00:00:00                7
2012-05-17 00:00:00                8
2012-05-18 00:00:00                9
2012-05-19 00:00:00                6


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>