If we now want to know how many movies more recent or equal to 1960 are in the Video Library.
The code 4D would be:
C_LONGINT($NoMovies)
$NoMovies:=0
REDUCE SELECTION([MOVIES];0)
QUERY([MOVIES];[MOVIES]Year_of_Movie>=1960)
$NoMovies:=Records in selection([MOVIES])
ALERT("The Video Library contains "+String($NoMovies)+" movies more recent or equal to 1960")
- Using the generic SQL commands, the above query becomes:
C_LONGINT($NoMovies)
$NoMovies:=0
REDUCE SELECTION([MOVIES];0)
SQL LOGIN(SQL_INTERNAL;"";"")
SQL EXECUTE("SELECT COUNT(*) FROM MOVIES WHERE Year_of_Movie >= 1960";$NoMovies)
SQL LOAD RECORD(SQL all records)
SQL LOGOUT
ALERT("The Video Library contains "+String($NoMovies)+" movies more recent or equal to 1960")
- Using the QUERY BY SQL command, the above query becomes:
C_LONGINT($NoMovies)
$NoMovies:=0
REDUCE SELECTION([MOVIES];0)
QUERY BY SQL([MOVIES];"Year_of_Movie >= 1960")
$NoMovies:=Records in selection([MOVIES])
ALERT("The Video Library contains "+String($NoMovies)+" movies more recent or equal to 1960")
As in the previous section, in order to test all the above examples, simply launch the "4D SQL Code Samples" database and go to the main window. You can then choose the query mode and press the WHERE clause button.