Command SQL Professional

Executes an SQL statement

Syntax
SQL <statement> [VIA <session>]
or
SQL <statement> INTO <variable> [VIA <session>]
or
SQL CMD <statement> [VIA <session>]
Parameters
<statement>
The <statement> parameter is the SQL statement to be executed. After execution, a workarea is open where results can be fetched.
<variable>
The <variable> designates a variable that will hold the result of the SQL statement. This is useful if the statement returns one result only, like SELECT AVG(*). There is no workarea open after execution of this command.
<statement>
The argument <statement> will be executed but no result or workarea is made available. This command is useful to submit SQL statements not delivering any results.
<session>
The argument <session> explicitly determines the session where the SQL statement is to be executed. If <session> was not passed, the return value of DbSession() or DacSession():getDefault() is used.
Description

The command SQL executes an SQL statement. Depending on which one of the various forms has been used, a workarea is open after execution to fetch the results.

Examples
SQL
// This example shows how to use the various 
// forms of the SQL command. 

#include "sqlcmd.ch" 

PROCEDURE main(cDsn) 
LOCAL x, oSession 
LOCAL cSqlCmd 

     CREATE CONNECTION INTO oSession DATASOURCE (cDsn) 

     // execute an SELECT statement 
     // and show results 
     SQL "SELECT * FROM customer WHERE custId > 1000" 
     LIST ALL 
     CLOSE 

     // get the sum of orders into the variable x 
     SQL "SELECT SUM(price) FROM orders WHERE order_id = 1000" INTO x 
     ? "Total of order 1000:", x 


     // execute an SQL statement on the server 
     // which does not return any results 
     SQL CMD "SET LANGUAGE 'Italiano'" 
     // check if the command had any effect 
     SQL "SELECT @@LANGID AS 'Language ID'" INTO x 
     ? "Language-Id:", x 

     // declare long SQL statements in TEXT-blocks 
     // and store it into a variable 
     TEXT INTO cSqlCmd 
         SELECT @@CONNECTIONS AS 'Login Attempts', 
               GETDATE() AS 'Today''s Date and Time' 
     ENDTEXT 
     // submit command using a variable holding 
     // the SQL statement 
     SQL (cSqlCmd) 
     LIST ALL 
     CLOSE 
RETURN 

PROCEDURE DbeSys 
   DbeLoad( "ODBCDBE" ) 
   DbeSetDefault( "ODBCDBE" ) 
RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.