Batches and Control-of-Flow Language

Transact-SQL allows you to group a series of statements as a batch, either interactively or from an operating system file. You can also use Transact-SQL control-of-flow language to connect the statements, using programming constructs.

A variable is an entity that is assigned a value. This value can change during the batch or stored procedure in which the variable is used. SAP ASE has two kinds of variables: local and global. Local variables are user-defined, whereas global variables are predefined, and are supplied by the system during command execution.

SAP ASE can process multiple statements submitted as a batch, either interactively or from a file. A batch or batch file is a set of Transact-SQL statements that are submitted together and executed as a group, one after the other. A batch is terminated by an end-of-batch signal. With the isql utility, this is the word “go” on a line by itself. For details on isql, see the Utility Guide.

This batch contains two Transact-SQL statements:

select count(*) from titles 
select count(*) from authors 

A single Transact-SQL statement can constitute a batch, but it is more common to think of a batch as containing multiple statements. Frequently, a batch of statements is written to an operating system file before being submitted to isql.

Transact-SQL provides special keywords called control-of-flow language that allow users to control the flow of execution of statements. You can use control-of-flow language in single statements, in batches, in stored procedures, and in triggers.

Without control-of-flow language, separate Transact-SQL statements are performed sequentially, as they occur. Correlated subqueries, are a partial exception. Control-of-flow language permits statements to connect and to relate to each other using programming-like constructs.

Control-of-flow language, such as if...else for conditional performance of commands and while for repetitive execution, lets you refine and control the operation of Transact-SQL statements. The Transact-SQL control-of-flow language transforms standard SQL into a very high-level programming language.