Posted - 08/19/2013 : 19:16:07
| Table DateRangeTab (Fromdate, Todate, TotalValue) has data such as:
2010-01-01, 2011-01-01, 0
2010-01-01, 2012-01-01, 0
etc (i.e lots of date ranges all with 0 in the TotalValue column)
I also have table ValueTab (DateofValue, Value) which has data such as:
etc (i.e. lots of different rows with dates and a value for each date)
I need to update DateRangeTab TotalValue column with SUM of Value from ValueTab table where the DateofValue falls in the range FromDate - Todate.
I tried something like the following :
set TotalValue = a.Value
select sum(value) as Value from ValueTab VT join DateRangeTab DT on VT.DateofValue between DT.startdate and DT.ToDate) a
But it puts same total in each row of the DateRangeTab.
Hope someone can help or direct me to another post with a related answer.