Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Filtering using certain conditions
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP1
Network:
Windows 2000 Server
Database:
Visual FoxPro
Divers
Thread ID:
01075616
Message ID:
01075626
Vues:
13
>I am trying to set a filter on a table with 4 variables which work great if all 4 variables have information. How can I set this up if say only 2 out of the 4 have information. My code is currently:
>
>
>SELECT planrep
>SET FILTER TO INLIST(planrep.dept,&lcdept) AND INLIST(planrep.factory,&lcfactory) AND INLIST(planrep.country,&lccountry) AND INLIST(planrep.season,&lcseason)
>
>
>There may be a time that I only want to filter by just lcseason.


Two ways (I like second more)

Change TYPE([.....]) to condition that match, becuase I didn't know what you mean variable doesn't have info. Is that variable is EMPTY() but declared or it is not declared at all.

1.
SELECT planrep
SET FILTER TO IIF(TYPE(lcdept)    # "U",INLIST(planrep.dept,&lcdept),.t.)       AND;
              IIF(TYPE(lcfactory) # "U",INLIST(planrep.factory,&lcfactory,.t.)  AND;
              IIF(TYPE(lccountry) # "U",INLIST(planrep.country,&lccountry),.t.) AND;
              IIF(TYPE(lcseason)  # "U",INLIST(planrep.season,&lcseason), .t.)
2.
LOCAL lcFilterCondition
lcFilterCondition = []

IF TYPE(lcdept) # "U"
  lcFilterCondition = [INLIST(planrep.dept,]+m.lcDept+[)]
ENDIF

IF TYPE(lcfactory) # "U"
   lcFilterCondition = lcFilterCondition +;
                       IIF(EMPTY(lcFilterCondition),[],[ AND ])+;
                       [INLIST(planrep.factory,]+lcfactory+[)]
ENDIF

IF TYPE(lcseason) # "U"
   lcFilterCondition = lcFilterCondition +;
                       IIF(EMPTY(lcFilterCondition),[],[ AND ])+;
                       [INLIST(planrep.season,]+lcseason+[)]
ENDIF

IF TYPE(lccountry) # "U"
   lcFilterCondition = lcFilterCondition +;
                       IIF(EMPTY(lcFilterCondition),[],[ AND ])+;
                       [INLIST(planrep.lccountry,]+lccountry+[)]
ENDIF

IF NOT EMPTY(lcFilterCondition)
   SET FILTER TO &lcFilterCondition
ELSE
   SET FILTER TO
ENDIF
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform