Variables inside bookmarks ΒΆ

Inside a query, you can also add placeholders for variables. This is done by inserting into the query SQL comments between /* and */. The special string [VARIABLE{variable-number}] is used inside the comments. Be aware that the whole query minus the SQL comments must be valid by itself, otherwise you won't be able to store it as a bookmark. Also, note that the text 'VARIABLE' is case-sensitive.

When you execute the bookmark, everything typed into the Variables input boxes on the query box page will replace the strings /*[VARIABLE{variable-number}]*/ in your stored query.

Also remember, that everything else inside the /*[VARIABLE{variable-number}]*/ string for your query will remain the way it is, but will be stripped of the /**/ chars. So you can use:

/*, [VARIABLE1] AS myname */ 

which will be expanded to

, VARIABLE1 as myname 

in your query, where VARIABLE1 is the string you entered in the Variable 1 input box.

A more complex example, say you have stored this query:

SELECT Name, Address FROM addresses WHERE 1 /* AND Name LIKE '%[VARIABLE1]%' */ 

If you wish to enter "phpMyAdmin" as the variable for the stored query, the full query will be:

SELECT Name, Address FROM addresses WHERE 1 AND Name LIKE '%phpMyAdmin%' 

NOTE THE ABSENCE OF SPACES inside the /**/ construct. Any spaces inserted there will be later also inserted as spaces in your query and may lead to unexpected results especially when using the variable expansion inside of a "LIKE ''" expression.