Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL inner join query challenge
Message
 
 
À
10/11/2009 14:15:56
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Database:
Visual FoxPro
Divers
Thread ID:
01434050
Message ID:
01434103
Vues:
32
>>See some changes inside - however, I need again the input tables with BillCodes - something is not entirely right now in this schema.
>
>
>Model table
>---------------
>Modelid     Name
>100           180 BR
>110           225 SCR
>
>
>Option Table
>-----------------
>
>optionid      name                               ispackage
>-----------      --------------------------             ---------------
>100            Deluxe Stereo  Package     1
>110            Sony 6 Disc Changer          0
>120            100 Watt subwoofer            0
>130            Swim transom remote         0
>
>Modeloption table
>-------------------------
>
>modelid           optionid             packageid             billcode
>100                 100                   0                          DLXSTREO180BR
>100                 110                   100                      SNYSTERO
>100                 130                   100                      SWMTANSREMO
>110                 100                   0                          DLXSTREO225SCR
>110                 110                   100                      SNYSTERO
>110                 120                   100                      SUBWOOF
>110                 130                   100                      SWMTANSREMO         
>
>
>
>You will notice that the packages can be different for different models. the 180BR doesn't have a subwoofer in this example.
>
>If I was doing this in VFP for the entire project it wouldn't be so hard to break it up... but this dataset needs to be realtime queriable from Excel. I'm looking into doing a stored procedure and brute force the data into shape with multiple queries/processing if I have to.
>
>Thanks again for all your help

Please see this modified SQL - if it would not work, I'll take a closer look tonight - need to run now.
SELECT model.name as modelname, pnm.optionid as Packageoptionid, pnm.Name AS PackageName,  
iif(Mo.PackageID = 0, Mo.BillCode, space(20)) as PackageBillCode, 
iif(Mo.PackageID <> 0, Mo.BillCode, space(20)) as OptionBillCode, ;
onm.Name AS OptionName, onm.optionid as Optionid, mo.billcode as OptionBillCode ;
	FROM modeloption mo ;
		JOIN Option AS pnm ON pnm.optionid = mo.OptionID and mo.PackageID = 0 ;
		JOIN Option AS onm ON onm.optionid = mo.Optionid  and mo.PackageID <> 0;
		JOIN model ON model.modelid = mo.modelid ;
    WHERE  model.name LIKE "%-10%"; 
    ORDER by model.sortorder, pnm.optioncatid, pnm.sortorder, onm.sortorder
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform