User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 425,899 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,923 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 757 | Replies: 2
Reply
Join Date: Jun 2008
Posts: 4
Reputation: tkotey is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tkotey tkotey is offline Offline
Newbie Poster

SUM two fileds from different rows from the same table

  #1  
Jun 25th, 2008
I would like to SUM two fileds from different rows from the same table but I don't know how to do that.

E.g.

BillingTransactionsIndex CreateDate UserType UserIndex TransType Reference Total Balance
2 6/5/2008 15:02 1 51 1 150 -288.2 -288.2
5 6/8/2008 11:55 1 51 1 157 -1.58674 -289.787

In the table above I want SUM fields Total and Balance for the first row and the the next row SUM 2nd row Total with 1st row Balance

Please help

Thanks
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2008
Posts: 4
Reputation: tkotey is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tkotey tkotey is offline Offline
Newbie Poster

Re: SUM two fileds from different rows from the same table

  #2  
Jun 25th, 2008
I want this

Total Balance
row 1 90 90
row 2 23 113
row 3 15 128
row 4 20 148

In row 2 to get the balance I SUM Balance(90) of row 1 with Total(23) of row 2 to get Balance (113) of row 2. Same thing is done for the next row by adding with Balance of previous row
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: SUM two fileds from different rows from the same table

  #3  
Jun 25th, 2008
Hi tkotey

Similar problem we have discussed on http://www.daniweb.com/forums/thread127644.html.
you may investigate SQL code from posts #5 and #7 where I gave solutions on how to compute balance values from consecutive rows. You can adapt that code so it fits your specific requirements. If you have further problems we can discuss them here.

krs,
tesu
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 7:36 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC