I appreciate the response but that's not what I'm looking for here. My apologies for not making myself clear. I'll try to add more detail.Given the Table:Create Table #Mytable(mydate datetime not null, myvalue numeric(10,6) not null, mysize numeric(10,6) not null)Insert Into #MyTable(mydate, myvalue, mysize)Select '1/1/1900 12:00 PM', 1.0, 5 UNION ALLSelect '1/1/1900 12:01 PM', 1.1, 5 UNION ALLSelect '1/1/1900 12:02 PM', 1.0, 4 UNION ALLSelect '1/1/1900 12:03 PM', 1.2, 6 UNION ALLSelect '1/1/1900 12:04 PM', 0.9, 5 UNION ALLSelect '1/1/1900 12:05 PM', 1.0, 6
I would like to get back a rolling average of myvalue where the sample size includes the current datapoint and however many previous data points is takes to get sum(mysize) >= 10.so the result I'm looking for ismydate RunAvg Sum(MySize)1900-01-01 12:00:00.000 NULL 5 1900-01-01 12:01:00.000 1.050000 101900-01-01 12:02:00.000 1.033333 141900-01-01 12:03:00.000 1.100000 101900-01-01 12:04:00.000 1.050000 111900-01-01 12:05:00.000 1.025000 11