A T-SQL variable is used in a batch or routine that does not declare it

tx0/sql:undeclared-variablerecommendederrorreliability/logicdepth fastbug

What it finds

In T-SQL, a variable must be declared in the batch or routine that uses it; one that is not makes the batch fail with "must declare the scalar variable". A GO between the declaration and the use is a common cause: it ends the batch, and the variable with it.

From the rule's source, undeclared_variable.rs.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/sql:undeclared-variable" = "error"

To keep one finding, suppress it with a reason: tx0 suppress ID --reason "..." writes the comment for it.

tx0 explain tx0/sql:undeclared-variable shows the same in the terminal. Found a false positive? Report it.