set

Evaluates expressions using functions or the like and then assigns that value to the parameter.

Syntax

set VAR_NAME=EXPR
Required Parameters
VAR_NAME = EXPR
Value obtained by evaluating the expression to the query parameter. On the right side of the command, you can use any expression that can be evaluated without a record at the time the query is executed.
  • It works regardless of whether whitespaces are inserted before or after the assignment operator (=).
  • You can use any expression that can be evaluated without a record at the beginning of the query.
  • The query parameter is valid for one query instance while it is alive.
  • If there are multiple set commands, they are evaluated in order from the left.

Description

The query parameter is valid for one query instance while it is alive, and you can use the set command to evaluate the parameter value at the time the query is parsed. The query string below is an example of using the table command to dynamically query data from 00:00 hour three days before to before 00:00 hour on the current day.

set from = string(dateadd(now(), "day", -3), "yyyyMMdd")
| set to = string(now(), "yyyyMMdd")
| table from=$("from") to=$("to") sys_cpu_logs

You can use the set command to set the query parameter as described above, and you can use the $() function to refer the value of the query parameter.

The options of each query command can be replaced with query parameters. For example, you can use query parameters when executing a scheduled query, if you want to look up and process data for a week range based on the current date, or if you want to execute a query using the parameter value you provide when running the procedure.

When you call the procedure, the values passed to the procedure's parameters are set as query parameters. Therefore, when you create or edit a procedure, you can use it with a $() function by assuming that the query string already has a value corresponding to the procedure parameter.