END-EXEC
END-EXEC is a keyword in SQL that marks the end of a dynamically executed SQL statement within a program. It serves to separate SQL statements from the host language code, ensuring the successful execution of the SQL command.
Example
EXEC SQL SELECT * INTO :variable FROM table_nameEND-EXEC;
Output
Assuming the output of the query was stored in a variable called ‘variable’, the output should be the values from the selected column of the table.
Explanation
The END-EXEC statement is used to mark the end of an SQL statement within a host program. The above code simply retrieves data from a table. The keyword INTO
leading with :
is used to represent the host variable where the retrieved data is stored. The keyword FROM
is indicating the table to extract data from.
Example
EXEC SQLSELECT * From EmployeeEND-EXEC;
Output
Id | Name | Position-- | ---- | --------1 | John | Manager2 | Jane | Analyst3 | Bob | Developer
Explanation
In the example, the EXEC SQL
and END-EXEC
statements indicate the beginning and end of SQL commands. The SQL statement SELECT * FROM Employee
retrieves all data from the Employee
table. Output represents the returned rows from the table. Note: EXEC SQL
and END-EXEC
are largely used in embedded SQL in languages like C and COBOL, SQL Server does not use these commands.