Friday, March 23, 2012

Running sum?

Is there running sum function in MS SQL Server 2000 like a property in MS
Access?
In advance thank you,
Stanko Milosev
work:
stanko@.nospam--netcomp.co.yu
www.netcomp.co.yu
home:
stanko@.nospam.milosev.co.yu
www.milosev.co.yuStanko Milosev,

> Is there running sum function in MS SQL Server 2000 like a property in MS
> Access?
No, there is not such function in SQL Server, but you can calculate it.
Example:
use northwind
go
create table t1 (
c1 int not null identity unique,
c2 numeric(9, 2)
)
go
insert into t1(c2) values(193.51)
insert into t1(c2) values(194.5)
insert into t1(c2) values(202.71)
insert into t1(c2) values(192.79)
insert into t1(c2) values(197.6)
insert into t1(c2) values(192.9)
insert into t1(c2) values(192.76)
insert into t1(c2) values(191.91)
insert into t1(c2) values(187.9)
go
select
a.c1,
a.c2,
sum(b.c2) as running_sum_c2
from
t1 as a
left join
t1 as b
on a.c1 >= b.c1
group by a.c1, a.c2
order by a.c1
go
drop table t1
go
AMB
"Stanko Milosev" wrote:

> Is there running sum function in MS SQL Server 2000 like a property in MS
> Access?
> In advance thank you,
> Stanko Milosev
> work:
> stanko@.nospam--netcomp.co.yu
> www.netcomp.co.yu
> home:
> stanko@.nospam.milosev.co.yu
> www.milosev.co.yu
>
>|||I think that the running sum is a function of Access, not the Jet database.
Alejandro gave you a working solution.
You can test it out but you should also test doing the calculations client
side.
You may find (I'm tempted to say "probably") that it will perform better
doing it client side.
"Stanko Milosev" <stanko@.nothing.com> wrote in message
news:Ou7qBQH4FHA.2676@.TK2MSFTNGP15.phx.gbl...
> Is there running sum function in MS SQL Server 2000 like a property in MS
> Access?
> In advance thank you,
> Stanko Milosev
> work:
> stanko@.nospam--netcomp.co.yu
> www.netcomp.co.yu
> home:
> stanko@.nospam.milosev.co.yu
> www.milosev.co.yu
>|||Thank you all, we solve the problem,
Stanko.
"Stanko Milosev" <stanko@.nothing.com> wrote in message
news:Ou7qBQH4FHA.2676@.TK2MSFTNGP15.phx.gbl...
> Is there running sum function in MS SQL Server 2000 like a property in MS
> Access?
> In advance thank you,
> Stanko Milosev
> work:
> stanko@.nospam--netcomp.co.yu
> www.netcomp.co.yu
> home:
> stanko@.nospam.milosev.co.yu
> www.milosev.co.yu
>

No comments:

Post a Comment