Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem to make a report
Message
 
 
To
01/06/2009 15:15:17
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01403052
Message ID:
01403055
Views:
57
>ok i have 3 table in my databases. TB_ACCOUNT(containt all the customer account),TB_INVOICE(containt all the customer invoices),TB_SALESMAN(containt all my salesman). In the tb_account in a field name tr_idsalemans. and in the invoice i have a field name tr_idaccount. so i want to be able when i select a salesment to have all of the account that he have and have the last invoice amount that the customer ordered. it is possible to make it in one sql statement or more. how can i do it thanks

Try
select S.*, AC.*, In.* from Tb_Salesman S LEFT JOIN TB_Account Ac on S.tr_idsalemans = Ac.tr_idsalemans 
LEFT JOIN 
(select tr_idaccount, Amount from TB_INVOICE Inv1 
INNER JOIN (select tr_idaccount, max(Inv_Date) as MaxInDate) MaxDates ON 
Inv1.tr_idaccount = MaxDates.tr_idaccount and Inv1.Date = MaxDates.MaxInDate) In
on Ac.tr_idaccount =In.tr_idaccount
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform