KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Use QUERY WITH ARRAY to Clean Up Your Code
PRODUCT: 4D | VERSION: 16 | PLATFORM: Mac & Win
Published On: November 28, 2017

When writing a query, it is often necessary to pass in multiple parameters to refine a search.

If using QUERY or QUERY SELECTION to do a search, it is easy to clean up the look of the code by using the QUERY WITH ARRAY or QUERY SELECTION WITH ARRAY commands instead. This change reduces the number of requests made to the server, which can speed up the performance of the application.

For example, running a query on the sample table [myTable] where the field [myTable]strField contains certain keywords, it is possible to write the query like:

QUERY ([myTable];[myTable]strField="apple";*)
QUERY ([myTable]; | [myTable]strField="mango";*)
QUERY ([myTable]; | [myTable]strField="orange";*)
QUERY ([myTable]; | [myTable]strField="seaweed";*)
QUERY ([myTable]; | [myTable]strField="strawberry")


Or that same query can be written using QUERY WITH ARRAY where an array stores the search values, and the code is more cleanly written:

QUERY WITH ARRAY([myTable]strField;$mySearchArray)