IBM developerWorks
           MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old June 21st, 2004, 10:27 AM
bhogg bhogg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 bhogg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
"Running Balance" query

Hi,

I'm still in the data modelling stage, and have read over some general ledger database design principles, but wondering if someone can help with a query I'm looking to generate.

Currently, all transactions would be placed in the Transactions table, which is the basic equivalent to a general ledger. I'm not maintaining a running balance column, since it can be calculated. But of course, one of the main screens/reports will be an account history with the running balance to date beside each transaction.

Is there a way, while the SQL statement is grabbing the transaction table (sorted by Date) to keep a running tally of the Amount column? Otherwise, I'd have to grab the table without the running balance, and do another query for each transaction - summing the Amounts before the current transaction date. Or just do it in code with the returned table.

Any suggestions?

Thanks,
Brian

Reply With Quote
  #2  
Old June 22nd, 2004, 11:11 AM
lucasalexander lucasalexander is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Location: Atlanta
Posts: 39 lucasalexander User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via AIM to lucasalexander Send a message via MSN to lucasalexander
I'd probably try to do it in the application instead of in the database, but if you've got to do it in the database, you could use a cursor to loop through each record and calculate the running balance. I'd stay away from the cursor for performance reasons, but I think it would still be better than executing a separate SQL query for each transaction.

Lucas Alexander
http://www.alexanderdevelopment.net

Reply With Quote
  #3  
Old June 22nd, 2004, 12:13 PM
bhogg bhogg is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 bhogg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sounds good. Was hoping there was a way to do it, since it's needed in every account program (that I know of). There's probably a way to redesign the database around it, but there's probably no point for this one issue.

Thanks again,
Brian

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > "Running Balance" query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway