Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Building a WHERE clause
Message
 
À
11/12/1998 12:25:35
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00166558
Message ID:
00166687
Vues:
11
>>>Does anyone have a good function/procedure/class that can build n-sized WHERE clauses? That is, I want to be able to pass it something like an array full of populated or empty fields and have it automatically add any needed " AND ". So I could do something like:
>>>
>>>lnElements = 4
>>>DIMENSION laFilter[lnElements]
>>>
>>>laFilter[1] = "One"
>>>laFilter[2] = ""
>>>laFilter[3] = "Three"
>>>laFilter[4] = "Four"
>>>
>>>oSQL.Where(@laFilter)
>>>
>>>?oSQL.WhereClause
>>>
>>>One AND Three AND four
>>
>>Please don't take this as a critcism, but you are looking for a class to replace 3-4 lines of code MAX. If you write it yourself as straightforward in-line code you will save memory and it'll probably execute faster too.
>
>This is not true. If you want to build a QBF interface that allows users to select as many or as few filters from x number of fields, then you need a class like this. You can not code it straight in line, because you don't want irrelevant filters in your WHERE clause.
>
>I have had need for a class like this many times, but have never yet taken the time to build a generic one, I have just handled it per situation so far.
>
>I, too will be watching this thread for ideas.

lcWhere = ''
FOR i=1 TO ALEN(laFilter)
IF i = 1
lcWhere = ALLT(laFilter[i])
ELSE
IF ! EMPTY(laFilter[i])
lcWhere = lcWhere + ' AND ' + ALLT(laFilter[i])
ENDIF
ENDIF
NEXT i

Wouldn't something like that work? Obviously you could get more elaborate.

Wayne
Wayne Myers, MCSD
Senior Consultant
Forte' Incorporated
"The only things you can take to heaven are those which you give away" Author Unknown
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform