Sql

Sql allows you to execute a Select statement in the database.

Syntax

 For (VARIA_LIST) From DATAB_TYPE Sql SQL_STATEMENT As [CLASS]Next

Examples

 # Example 1: Request to select a maximum value in a tableLocal Char REQUEST(255)REQUEST="select max(ACCNUM_0) From GACCENTRYD"For (Integer NUM) From "3" Sql REQUETE As [XXX]MAX_VAL=[F:XXX]NUMNext# Example 2: Request to select the different fields of a table in data dictionaryLocal Char REQUEST(255)Local Char MYTABLE(20)...REQUEST="select CODZONE_0, DIME_0 From ATABZON Where CODFIC='"+MYTABLE+"'"For (Char FIELD(12),Integer DIMENSION) From "3" Sql REQUETE As [ABB]# Here, we have for every loop FIELD that is equal to the column name and DIMENSION to its dimensionNext# Example 3: Request with an arrayLocal Char REQUEST(255)(1..5)REQUEST(1)="select BPCNAM_0"REQUEST(2)=" From BPARTNER"REQUEST(3)=" Where BPCFLG_0=1"# First request without whereFor (Char NAMES(20))From "S" Sql REQUEST(1..2) As [BPC]# All the lines will be seenNext# Second request with the where For (Char NAMES(20))From "S" Sql REQUEST(1..3) As [BPC]# Only the lines with BPCFLG_0 equal to 1 will be seenNext# Example 3: Use the default databaseLocal Integer DBTYPELocal DATABASE_TYPE(10)DBTYPE = fmet GACTX.APARAM.AGETVALNUM([V]CST_ALEVFOLD,"","TYPDBA")DATABASE_TYPE=string$(DBTYPE=1,"O")+string$(DBTYPE=2,"S")For (Integer INDEX,Char NAMES(20)(1..2)) From DATABASE_TYPE SQL "Select INDEX_0, NAME_0, NAME_1 From MYTABLE" As [MYT]# On every loop instance, we have the following values available:# [MYT]INDEX, [MYT]NAMES(1), [MYT]NAMES(2) Next

Description

Sql allows you to execute a Select statement on the database. The list of parameters in this syntax will be filled by the data returned in every loop for one of the lines of the cursor.

The database type is given by the following values:
* "o","O","3" indicates Oracle.
- "s","S","5" indicates SQL server.

The SQL expression can be given with a string array. When this happens, all the lines of the array (limited to a range if a range is given) are concatenated to give the SQL request to be executed.

The class abbreviation is used to access the variables in the list.

Associated errors

Error codeDescription
19Database incorrect: the database type is not Oracle or SQL server.
69Incorrect arguments: the argument list has less or more than the number of columns returned by the select statement, or the data type does not fit with the columns returned.
75Database error: a column mentioned in the SQL statement does not exist.

See also

Anasql, Execsql.