Thursday, March 8, 2012

Cumlative totals

I am developing a table in SQL Server for data analysis, and what i want to
do is have a cumlative total field. Is there a way when I am doing an insert
data, I could populate a column with a running total?
Thanks.Lyners,
Yes - one option is to create a trigger on the table to update the cumlative
total field.
HTH
Jerry
"Lyners" <Lyners@.discussions.microsoft.com> wrote in message
news:A408D891-7199-4B21-9F18-E6E88FE2C434@.microsoft.com...
>I am developing a table in SQL Server for data analysis, and what i want to
> do is have a cumlative total field. Is there a way when I am doing an
> insert
> data, I could populate a column with a running total?
> Thanks.|||the update and delete triggers might be quite involved.
Under most circumstances I would rather write a select query
calculating running totals - that would be way simpler|||Maybe...but Lyners just mentioned INSERTs so that doesn't seem too involved.
But agreed a stored procedure could be created to update the running total
column and then scheduled as a job for non peak hours.
HTH
Jerry
"Alexander Kuznetsov" <AK_TIREDOFSPAM@.hotmail.COM> wrote in message
news:1127943367.558805.246800@.g47g2000cwa.googlegroups.com...
> the update and delete triggers might be quite involved.
> Under most circumstances I would rather write a select query
> calculating running totals - that would be way simpler
>|||On Wed, 28 Sep 2005 14:13:05 -0700, Lyners wrote:

>I am developing a table in SQL Server for data analysis, and what i want to
>do is have a cumlative total field. Is there a way when I am doing an inser
t
>data, I could populate a column with a running total?
>Thanks.
Hi Lyners,
Why not create an indexed view, and have SQL Server do all the hard work
of changing the running total when the underlying data changes?
Look up CREATE UNIQUE CLUSTERED INDEX in Books Online.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||I made a procedure that uses a curser that goes through and updates all of
the running totals. Very fast and easy.
Thanks!
"Jerry Spivey" wrote:

> Maybe...but Lyners just mentioned INSERTs so that doesn't seem too involve
d.
> But agreed a stored procedure could be created to update the running total
> column and then scheduled as a job for non peak hours.
> HTH
> Jerry
> "Alexander Kuznetsov" <AK_TIREDOFSPAM@.hotmail.COM> wrote in message
> news:1127943367.558805.246800@.g47g2000cwa.googlegroups.com...
>
>

No comments:

Post a Comment