Variable Reference

Syntax

{&varname <format=formats> before="string1 between="string2" after="string3"}

Required Arguments

&varname
varname is the name of the variable. If the variable that you want to reference was specified in the URL with more than one value, you can use the following syntax to reference a single specific value, a range of values, or all values:
&varname[n]
references the nth value that the variable contains where n>=1.
&varname[m..n]
references all values from the mth value to the nth value, where m<=1<n and the variable contains two or more values.
&varname[*]
references all values that the variable contains.
In the first two instances, m and n can be references to numeric variables.
before="string1"
between="string2"
after="string3"
These parameters enable you to output strings of characters before, between, and after variable values. You can use an unlimited number of characters in your strings (note that the maximum number of characters that you can use depends on how much memory your system has). If you want to include double quotation marks within your string, then delimit the string with single quotation marks or use two double quotation marks within your string. For example, both of the following values return the string "How are you?":
between='"How are you?"'
between="""How are you?"""
To include single quotation marks within your string, delimit the string with double quotation marks or use two single quotation marks within your string. For example, both of the following values return the string What's up?:
before="What's up?"
before='What''s up?'
The default value for before= is a null string (""). The default value for between= is a blank space (" "). The default value for after= is a null string ("").

Optional Argument

format=formats
formats is a single formatting option (format=value) or a comma-delimited list of options enclosed in parentheses (format=(value,...,valueN)). Do not use quotation marks to delimit the values. This is an optional parameter. See Formats for Variable Values and Labels for a list of formatting options.

Details

A variable reference is a string that htmSQL replaces with the value of a variable. Variables are symbols that are defined on the URL, columns that are selected by a query, or symbols that htmSQL automatically defines and supplies values for.
When htmSQL encounters a variable reference, it replaces the reference with the current value of the variable. If the reference is to a column in a results set and
  • the variable reference occurs before the SQL section, then the variable is undefined and cannot be resolved. The variable reference is written to stdout unresolved.
  • the variable reference occurs between the SQL section and the eachrow section, then htmSQL replaces the variable reference with the variable's value from the first row of the results set.
  • the variable reference occurs within an eachrow section, then htmSQL replaces the variable reference with the current row's value for the variable.
  • the variable reference occurs after the eachrow section, then htmSQL replaces the variable reference with the variable's value from the last row of the results set.
htmSQL also supports the resolution of nested variable references. That is, the value of a variable can itself be a variable that htmSQL can resolve. For example, if you have a variable named taxi, and the value of taxi is the variable name driver,
{&taxi} -----> driver
and the value of driver is Bob,
{&driver} -----> Bob
then when you specify {&{&taxi}}, htmSQL resolves the nested references to a value of Bob.
{&{&taxi}} -----> Bob
htmSQL can resolve an infinite number of these nested variable references.

Example

The following are examples of variable references:
{&myname}
{&weekdays[1..7]}
{&theworld[*]}
{&array1[{&counter}]}
{&array2[{&begin}..{&end}]}
{&months;[1..12] before="(" between="," after=")"}
{&{&varname}}
{&{&sys.colname[*]}}