Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with SQL including a SUM....
Message
From
17/08/2000 15:49:34
Peter Brama
West Pointe Enterprises
Detroit, Michigan, United States
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Help with SQL including a SUM....
Miscellaneous
Thread ID:
00406341
Message ID:
00406341
Views:
71
I have 3 files....

APMAS = master record for A/P
APDETL = invoices for A/P
APPAY = payments for invoices in A/P

These files are tied together by unique ID #'s for each file.

In "old school" programming, the rule of thumb was NOT to store totals of multiple records such as payments
towards invoices but to add them up again at the time of display. So, if I follow that thought....

I need to display in a listbox all the APDETL records for a selected client and also the total of all the payments
for the displayed APDETL record. An example would be

IVCDATE IVCNUM DUEDATE AMOUNT PAYMENT BALANCE
08/17/00 12345 08/17/00 $500.00 $100.00 $400.00

The payment is a sum of APPAY records for this invoice and the balance is the APDETL.amount - the total
of the payments.

I tried to due this with an SQL as follows:

select apdetl.ivcdate, apdetl.ivcnum, apdetl.duedate, apdetl.amount, sum(appay.amount), apdetl.amount-sum(appay.amount) ;
from apdetl left join appay ;
where apdetl.apmasid=apmas.apmasid and apdetl.apdetlid=appay.apdetlid ;
into cursor curLstApDetl ;
order by apdetl.ivcdate

but get a SYNTAX error. Is this the right track? What am I doing wrong? I thought of maybe
using a view but again couldn't figure out the SUM stuff. And I know, lots of people recommend
using a grid, but I hate grids and I want this to be a pick list, not one that they can edit or make
changes in. To get a grid to do this requires a great deal of "control" editing and then it doesn't
work 100% in my experience.

Suggestions?
Peter Brama
West Pointe Enterprises

VFP is getting easier but STILL alot to learn!!
Next
Reply
Map
View

Click here to load this message in the networking platform