Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query with a running total
Message
 
To
19/07/2006 09:12:55
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01137566
Message ID:
01137577
Views:
20
This message has been marked as the solution to the initial question of the thread.
>Hi all,
>
>Does VFP9 offer any simple solutions to the following situation?
>
>I am trying to create a view, which among others, has 4 fields- Date, Debit, Credit, and Balance-(which is the present running cash balance). For the Balance, it requires the (sum of all credits)-(sum of all debits), but only upto that date, or entry. My problem is, that when I specify it that way, I get only one row in the view, showing the total of all debits and all credits for the entire table. Could someone help me with this one ? Thanks.
>
>Regards,
>
>Steve.

Try:
SELECT Date, Debit, Credit,;
       NVL(SELECT SUM(Credit-Debit) FROM MyTable Tbl1 WHERE Tbl1.Date < MyTable.Date), CAST(0 AS N(12,2)) AS Balance;
       FROM MyTable
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform