Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
IN question
Message
 
 
À
01/09/2005 18:41:18
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01046060
Message ID:
01046065
Vues:
18
This message has been marked as a message which has helped to the initial question of the thread.
A couple of ways to do that. The macro substitution will work for limited # of selection. A cursor doesn't have limitation besides a speed.
*----------------------------------
* Macro substitution
LPARAMETERS tcCodeList, tlSelectAll
* tcCodeList = ['111', '222']
SELECT Test.code, Test.Desc ;
	FROM Test ;
	WHERE tlSelectAll OR Test.code IN (&tcCodeList) ;
	INTO CURSOR result
	
*----------------------------------
* A cursor 
CREATE CURSOR crsSelections (code C(3))
INSERT INTO crsSelections VALUES('111')
INSERT INTO crsSelections VALUES('222')

LPARAMETERS tcCursor, tlSelectAll
SELECT Test.code, Test.Desc ;
	FROM Test ;
	WHERE tlSelectAll OR Test.code IN (SELECT * FROM (tcCursor)) ;
	INTO CURSOR result
>
>I have a table - Test - that contains 4 records, as follows:
>
>
>Code    Desc
>111     Dog
>222     Cat
>333     Elephant
>444     Fish
>
>
>I want to give the user the ability to query on a variable number of code or 'ALL' the codes.
>
>In the following example, she has picked '111' and '222', so I constructed an array in the calling program with a length of 2. If she would have requested '111', '222', and '444', I would have had to construct an array of 3 members and some figured out how to accommodate
>the third member in my SQL syntax. If she requests all, then I need to set one of the members to ‘’ and since everything is equal to ‘’, all for records will be returned.
>
>Isn’t there a more elegant way to do this?
>
>
>
>LPARAMETERS taCodeList
>* taCodeList[1] = '111'
>* taCodeList[2] = '222'
>
>SELECT Test.code, Test.Desc ;
> FROM Test ;
>   WHERE Test.code IN(taCodeList[1],taCodeList[2]) ;
>   INTO CURSOR result
>
>
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform