If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Running Total

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-30-08, 13:40
ldykstra ldykstra is offline
Registered User
 
Join Date: Dec 2008
Posts: 2
Running Total

I am trying to total 3 different Running totals. Is this possible?

Here is an example of what I am trying to do. Let's say that there is a grouping on a job no 100 where I am totaling parts for that job. I have a running total on Part X, Part Y, Part Z. Is there a way to add up all of these parts? My problem is when one part isn't used for that job. It doesn't give me a total then.
Reply With Quote
  #2 (permalink)  
Old 12-30-08, 14:14
dportas dportas is offline
Registered User
 
Join Date: Dec 2007
Location: London, UK
Posts: 732
Please always say what version you are using. In 2005 use CUBE/ROLLUP. In 2008 use GROUPING SETS.

SELECT JobNo, PartNo, SUM(Quantity) Quantity
FROM Stock
GROUP BY PartNo,JobNo WITH ROLLUP;

SELECT JobNo, PartNo, SUM(Quantity) Quantity
FROM Stock
GROUP BY GROUPING SETS ((JobNo,PartNo),(PartNo),());
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On