version 11
The SQL standard has fairly restrictive rules about combining data of different types in expressions. Usually the DBMS is in charge of automatic conversion. However, the SQL standard requires that the DBMS must generate an error if you try to compare numbers and character data. In this context the CAST expression is very important, especially when we use SQL within a programming language whose data types do not match the types supported by the SQL standard.
You will find below the query of the Receiving an SQL query result into arrays section modified slightly in order to use the CAST expression.
The initial query in 4D code would be:
Using SQL code, the above query becomes:
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 Using CAST button.