Use host variables in an SQL statement
Host variables can be used in an SQL statement to represent a value that will be substituted in at execution time. The host variable syntax is a symbol followed by a string; for example, :companyname. The symbol used depends on the syntax your database vendor uses to denote variables.
- For Sybase and SQLServer, you would use @NAME , where NAME is the name of the host variable.
- For all others database vendors, you would use :NAME , where NAME is the name of the host variable.
You can use a host variable in your SQL statement in place of an expression. The Expression Builder can be used to create a host variable or you can simply type a host variable in place of an expression in the SQL Builder panes.
When you execute your statement in the SQL Builder you are prompted to substitute a value of the appropriate type for the host variable. Follow these steps to execute your statement containing a host variable and to substitute a value for the host variable:
- Open your statement in the SQL Builder.
- With focus on the SQL Builder, click SQL > Execute to execute the SQL statement. The Specify Variable Values window opens.
- In each row of the table that contains a host variable, double-click the cell under the Value heading, and then enter a value for the host variable.
- Click Finish.
After executing the statement, you can see what parameters were passed in by looking at the Parameters page in the DB Output view.
Parent topic
Editing an SQL statement
Related tasks
Executing an SQL statement