Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Best SQL syntax for me
Message
From
12/07/2009 00:50:57
Reza Meamar
Homa Programming Group
Shiraz, Iran
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Best SQL syntax for me
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01411663
Message ID:
01411663
Views:
76
Dear all
I have 3 table with below fields and recordes :
Admision.dbf
AdmCode – FileNum – OkXPha – XphaDate
 1  - 10  - .T. - 88/01/01
 2  - 11  - .T. - 88/01/02

Drg_Main.dbf
AdmCode –      Fee40     -     Fee41     -     Fee42
      1         -      100          -         0        -        0
      1         -      200          -         0        -        0
      2         -      300          -         0        -        0
      2         -      400          -         0        -        0
      2         -      500          -         0        -        0
     
Drg_Main_Ret.dbf
AdmCode –      Fee31
      1         -       50  
I have a SQL statement as below :
SELECT Admision.AdmCode, Admision.FileNum, Admision.OkXPha, Admision.XPhaDate AS 'RecDate', ;
SUM(Drg_Main.Fee40-Drg_Main.Fee41+Drg_Main.Fee42) AS 'SumFee', ;
SUM(Drg_Main_Ret.Fee31) AS 'SumRet' ;
FROM Admision ;
LEFT OUTER JOIN Drg_Main        ON Admision.AdmCode  = Drg_Main.AdmCode ;
LEFT OUTER JOIN Drg_Main_Ret ON Drg_Main.AdmCode = Drg_Main_Ret.AdmCode ;
WHERE Admision.OkXPha = .T. ;
GROUP BY Admision.AdmCode ;
ORDER BY Admision.XPhaDate,Admision.AdmCode ;
INTO CURSOR &Crs_DrgRep02 READWRITE
This must to extract data from 3 table and I want below result.
AdmCode – FileNum – OkXPha – RecDate – SumFee – SumRet
       1         -      10      -      .T.      -  88/01/01 -    300     -    50
       2         -      11      -      .T.      -  88/01/02 -  1200     -      0
I know that this SQL is wrong. Please help me to correct and optimize this.
thnaks
Next
Reply
Map
View

Click here to load this message in the networking platform