Your query is taking the sum of each day's amount, with the next amount within the same day (your partition and order by are on the same field). This is allowed, but it meanns one of three things:
- The TradingDate is a date, with multiple values on each date. If so, the sum is indeterminate, since you do not know which one would follow.
- TradingDate is poorly named, and it is really a date time. In this case, you are getting the next date time value, on the same date.
- Your query is misformed and you do not really mean "partition by TradingDate order by TradingDate".
I would speculate that you want one of two things. The first would be the sum of one day's Budget with the next day's. The other would be a cumulative sum.
There is the possibility that you have multiple rows per day and you want the sum of the budget on that day. If that's the case, then you can use the simpler formulation:
select TradingDate, Budget,
sum(Budget) over (PARTITION BY TradingDate) AS BudgetMTD
from #4