Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 SQL Help Needed in Sqlserver-2005

Author  Topic 

koushik
Starting Member

11 Posts

Posted - 2010-09-13 : 02:53:01
I have the following dataset :

Cust Prod MonthId Quantity
C1 P1 201001 5
C1 P1 201003 7
C2 P2 201002 7
C2 P2 201001 4
C2 P2 201003 6

And I want to generate the following :
Cust Prod MonthId Quantity QuantityYTD (Running Total) Comments
C1 P1 201001 5 5
C1 P1 201002 0 5 Dummy row need to be created for Month 201002 & C1, P1 combination
C1 P1 201003 7 12
C2 P2 201002 7 7
C2 P2 201001 4 11
C2 P2 201003 6 17


Can you please let me know the best way (query can give good performance) to achieve this.



Regards,
Koushik Chandra

CSears
Starting Member

39 Posts

Posted - 2010-09-13 : 13:25:22
Do you have a table that contains all the possible values for MonthID, Cust, and Prod?
Go to Top of Page
   

- Advertisement -