Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 20th, 2008, 09:00 PM
Authorized User
 
Join Date: Dec 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to devendar
Default Need Cumulative Query

Here is a table structure and sample data

Create TABLE Test1
(ID int,
 Value1 int)

INSERT INTO Test1 VALUES(1,600);
INSERT INTO Test1 VALUES(2,250);
INSERT INTO Test1 VALUES(3,200);
INSERT INTO Test1 VALUES(4,150);

But I need output like

ID Value1 Cumulative_Value
1 600 600
2 250 850
3 200 1050
4 150 1200

   I need a query for this...

Thanks in advance
 
Old March 20th, 2008, 09:05 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

How many rows are you talking about? It's important...

--Jeff Moden
 
Old March 20th, 2008, 09:29 PM
Authorized User
 
Join Date: Dec 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to devendar
Default

Query for n number of rows or atleast 5 rows
 
Old March 21st, 2008, 10:12 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Not exactly the estimate I was looking for... there's a huge difference between "N" rows and "at least 5 rows".

First example in the following article a very simple, classic method for running totals and running counts... it's also slow as hell for larger numbers of rows and the article explains why... (first piece of code is the example)...

http://www.sqlservercentral.com/articles/T-SQL/61539/

... and here's the article if you actually want some performance out of it...

http://www.sqlservercentral.com/arti...uerying/61716/

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
Cumulative % in Pivot Umasriram2 Excel VBA 0 August 7th, 2008 08:30 AM
Help: Running Sum (or Cumulative Sum) timdasa VB Databases Basics 1 August 22nd, 2006 03:12 PM
How to get Cumulative Sum of a Field badsy Crystal Reports 1 January 20th, 2006 05:09 PM
How to calculate cumulative values of query fields method Access 0 July 12th, 2005 08:53 AM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.