Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Which these 6 SQL select statements were just one (SQL guru)
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Which these 6 SQL select statements were just one (SQL guru)
Divers
Thread ID:
00271362
Message ID:
00271362
Vues:
49
Correct me if I'm wrong...but the following looks terrifyingly foolish, in part because it's using views of views of views...
Anyone crazy enough to try to put this mess into one view? Should I even try? Ahhhhh!!!

CREATE SQL VIEW "V_MO2" ;
AS SELECT Client.fname, Client.lname, Client.mi, ; Client.uniqueid, right(Voucher.faccode,3) as fac, Client.dateadm,;
Client.disdate, Client.curfac, Voucher.clicode, Voucher.vouseq,;
Voucher.lvlcode, Voucher.referappt, Voucher.contdate-1 as contdate,;
Voucher.unitsauth, Voucher.faccode ;
FROM kcpc!client ;
INNER JOIN kcpc!voucher ;
ON Client.code = Voucher.clicode ;
WHERE (Voucher.lvlcode = mlevel .or. Voucher.lvlcode = mlevel1 .or.;
Voucher.lvlcode = mlevel2) AND ( (Client.disdate = {} .AND. ;
Voucher.contdate > lvbom) .OR. (NOT Client.disdate = {} .AND. ;
Client.disdate >= lvbom .AND. Voucher.contdate > lvbom) ) ;
AND ASCAN(okcodes,Voucher.faccode) > 0

CREATE SQL VIEW "V_MO3" ;
AS sele dist v_mo2.*, 0.00 as used, 0.00 as usedthismo ;
FROM b2!V_mo2 ;
INNER JOIN kcpc!status ;
ON v_mo2.clicode = status.clicode ;
where (betw(status.startdate, v_mo2.referappt, v_mo2.contdate) .OR. betw(status.enddate, v_mo2.referappt, v_mo2.contdate) or status.enddate = {} .AND. status.startdate <= V_mo2.contdate) and (mlevel = '0000000004' and mclitype = 'M' and status.status = '3' or (mlevel # '0000000004' or mclitype # 'M') and ((?lcFundStat = 'FUNDED' .and. inlist(status.status,'1a', '1b', '3')) .Or. (?lcFundStat = 'NONFUNDED' .and. status.status = '2')))

CREATE SQL VIEW "V_MO4" ;
AS SELE mohist.clicode, mohist.vouseq, mohist.lvlcode, ;
sum(mohist.units) as used ;
FROM b2!moHist ;
INNER JOIN b2!v_mo3 ;
ON mohist.clicode = v_mo3.clicode ;
Where mohist.vouseq = v_mo3.vouseq and ;
mohist.lvlcode = v_mo3.lvlcode AND ;
(mohist.type = mclitype AND mohist.lvlcode = '0000000004' OR ;
mohist.lvlcode != '0000000004') ;
group by mohist.clicode, mohist.vouseq, mohist.lvlcode

CREATE SQL VIEW "V_MO5" ;
AS SELE mohist.clicode, mohist.vouseq, mohist.lvlcode, ;
sum(mohist.units) as usedthismo ;
from b2!mohist ;
INNER JOIN b2!v_mo3 ;
on mohist.clicode = v_mo3.clicode ;
Where mohist.vouseq = v_mo3.vouseq and ;
mohist.lvlcode = v_mo3.lvlcode AND ;
(mohist.type = mclitype AND mohist.lvlcode = '0000000004' OR ; mohist.lvlcode != '0000000004') and mohist.srvdate >= lvbom and ;
mohist.srvdate < lveom ;
group by mohist.clicode, mohist.vouseq, mohist.lvlcode

CREATE SQL VIEW "V_MO6" ;
AS SELECT V_mo3.clicode, v_mo3.lvlcode, v_mo3.LName, V_mo3.FName, ;
v_mo3.Mi, v_mo3.UniqueId , v_mo3.CurFac, v_mo3.Fac, ;
v_mo3.DateAdm, v_mo3.VouSeq, v_mo3.ReferAppt , ;
v_mo3.ContDate, v_mo3.Unitsauth, v_mo3.DisDate, ;
v_mo4.used, v_mo5.usedthismo ;
FROM b2!v_mo3 ;
Left Outer JOIN b2!V_Mo4 ;
ON v_mo3.clicode = v_mo4.clicode .and. ;
v_mo3.vouseq = v_mo4.vouseq ;
left outer JOIN b2!V_Mo5 ;
ON v_mo3.clicode = v_mo5.clicode .and. ;
v_mo3.vouseq = v_mo5.vouseq ;
Order By Lname, Fname, Mi

CREATE SQL VIEW "V_DATE_FILTERED" ;
AS SELECT v_mo6.*, mohist.units, .F. as AddUnits, ;
{ / / } as SrvDate ;
from b2!v_mo6 ;
Left Outer JOIN b2!mohist ;
ON v_Mo6.clicode = mohist.clicode .and. ;
v_mo6.vouseq = mohist.vouseq .and. ;
v_mo6.lvlcode = mohist.lvlcode ;
Where V_Mo6.contdate >= ?ldSrvDate .and. ;
v_Mo6.referappt <= ?ldSrvDate .and. .not. ;
Exist(SELECT Mohistwack.clicode ;
FROM b2!mohist as mohistwack ;
WHERE Mohistwack.clicode = v_mo6.CliCode AND ;
Mohistwack.lvlcode = v_mo6.LvlCode AND ;
Mohistwack.srvdate = ?ldSrvDate)
ICQ 10556 (ya), 254117
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform