Hi
create table #t (Account int,Period int, PeriodBal decimal(18,3))
insert into #t values (60001, 0, 365.88)
insert into #t values (60001, 1, 348.82)
insert into #t values (60001, 2, 534.55)
insert into #t values (60001, 3, -104.19)
insert into #t values (60001, 4, 958.12)
insert into #t values (60001, 5, -838.91)
insert into #t values (60001, 6, -2440.78)
insert into #t values (60001, 7, 5646.94)
select *,(select #t.PeriodBal+sum(t1.PeriodBal) from #t t1 where
t1.account=#t.account
and t1.period<=#t.period)
from #t
If it does not help please post a desired result
[quoted text, click to view] "Newman Emanouel" <newman@pascalpress.com.au> wrote in message
news:B4EBB306-F545-4DEB-AF4D-98340038FAC2@microsoft.com...
> Roy
>
> What you have suggested doesnt work, for some reason it does not sum the
> differenct period balances. All it does is just repeat the rows with the
> same
> amounts. What I need it to do is for the ytd bal of sap period 7 to add
> periodBal Period1 + periodBal Period2 + periodBal Period3 + .......
> periodBal Period7
>
> Does that make it clearer, the period is the month balance where month 1
> is
> Jan to Sept being period 9
>
> Regards
>
>
> "Roy Harvey (MVP)" wrote:
>
>> SELECT A.Period,
>> SUM(B.PeriodBal) as RunningBal
>> FROM TheTable as A
>> JOIN TheTable as B
>> ON A.Account = B.Account
>> AND A.Period >= B.Period
>> GROUP BY A.Period
>>
>> Roy Harvey
>> Beacon Falls, CT
>>
>> On Tue, 18 Sep 2007 20:34:01 -0700, Newman Emanouel
>> <newman@pascalpress.com.au> wrote:
>>
>> >Dear All
>> >
>> >I have a table I am using as shown below
>> >
>> >Account Period PeriodBal
>> >60001 0 365.88
>> >60001 1 348.82
>> >60001 2 534.55
>> >60001 3 -104.19
>> >60001 4 958.12
>> >60001 5 -838.91
>> >60001 6 -2440.78
>> >60001 7 5646.94
>> >
>> >What I need to do is to create a Ytd balance where it cumulates all the
>> >periods together. I am really stupped with the syntax required. Can
>> >anyone
>> >help please
>> >
>> >Regards
>> >
>> >Newman
>>