January 19, 2022 at 8:53 pm
Hi,
I have a statement per period. I want the periods to be cumulate. So column 1 must be 1, column 2 must be 1+2, colum3 must be 1+2+3 etc..
SELECT reknr, oms25_0, [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]
FROM dbo.View_balans_XXX_per_periode
ORDER BY reknr
Result:
I want to be the result as this:
January 19, 2022 at 10:47 pm
Use a running aggregate before you pivot?
SELECT n
, rt = SUM(t.n) OVER (order by n rows between unbounded preceding and current row)
FROM Testdb.dbo.tally t;
tally is just a table of numbers.
January 20, 2022 at 7:51 am
Thanks but how should I do this?
January 20, 2022 at 8:59 am
With no usable SQL or data to work with, maybe this is what you are looking for
SELECT reknr, oms25_0
, [1] = [1]
, [2] = [1] + [2]
, [3] = [1] + [2] + [3]
, [4] = [1] + [2] + [3] + [4]
, [5] = [1] + [2] + [3] + [4] + [5]
, [6] = [1] + [2] + [3] + [4] + [5] + [6]
, [7] = [1] + [2] + [3] + [4] + [5] + [6] + [7]
, [8] = [1] + [2] + [3] + [4] + [5] + [6] + [7] + [8]
, [9] = [1] + [2] + [3] + [4] + [5] + [6] + [7] + [8] + [9]
, [10] = [1] + [2] + [3] + [4] + [5] + [6] + [7] + [8] + [9] + [10]
, [11] = [1] + [2] + [3] + [4] + [5] + [6] + [7] + [8] + [9] + [10] + [11]
FROM dbo.View_balans_XXX_per_periode
ORDER BY reknr
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply