Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How do I select records based on a list
Message
From
01/07/2004 14:39:43
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00919766
Message ID:
00919777
Views:
21
Several options.

1) Create an inlist(), and then use macro expansion to execute your command. Limited in the number of options, since you can have something like 24 parameters (?) as a maximum.

2) Create your list in a string, for example: ',CAMP,JUV,ADULT,' The additional comma at the beginning and at the end is on purpose. Query:
Select... where "," + alltrim(KeyField) + "," $ MyList
This might be slow for very long lists. In any case, all records have to be analyzed; this is not Rushmore Optimizable.

3) Create a table or cursor with the allowed values.
select * from TargetTable;
  where KeyField in (select KeyField from AllowedValues)
This should relatively quickly, and with hardly any limitations, both for long lists, and for a large table.

>I have a listbox where a user selects multiple items. I am building a list with selected items and then I want to use that list to extract values from a table. The list can vary depending on how many thing the user selects from list box. How can I write a query based on items from the list.
>
>for example I have a list built using commas
>
>
>*lcList contains items selected from listbox
>*lcList contains values like 'CAMP,JUV,ADULT' etc.
>
>
>how do I write a query that selects units that contain values from lcList?
>
>for example:
>
>
select * from vehicle where v_unit = the lcList
>
>I can write
>
>select * from vehicle where v_unit = 'CAMP' or v_unit = 'JUV' or v_unit = 'ADULT'
>
>
>but my list can vary depending on items selected from list box and I don't how to write a query where v_unit can be dynamically used.
>
>thanks
>Nick
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform