version 11
Now we want to pass a variable to the SQL query containing the year (and not the year itself, hard-coded) and get all the movies released in 1960 or more recently. In addition, for each movie found, we also want information such as the year, title, director, media used and tickets sold. The solution is to receive this information in arrays or in a list box.
The initial query in 4D code would be:
Using SQL code, the above query becomes:
As you can see:
We can pass a variable ($MovieYear) to the SQL query using the same notation as for receiving parameters.
The SQL query result is saved in the aMovieYear, aTitles, aDirectories, aMedias and aSoldTickets arrays. They are displayed in the main window in two ways:
- Using a group of arrays:
- Using a list box having columns with the same names:
Using generic SQL commands, the above query becomes:
Using the QUERY BY SQL command, the above query becomes:
Using the SQL EXECUTE IMMEDIATE command, the query above becomes:
To test all the above examples, launch the "4D SQL Code Samples" database and go to the main window. You can then choose the query mode and press the SQL query results in arrays button.