Retired products

Find Unused Variables and Parameters

SQL Refactor can highlight any parameters or variables that are unused in the current script.

A parameter or variable is considered to be unused if it has been declared or assigned a value, but not queried or used in any control statements, and not used in INSERT or UPDATE statements, WHERE clauses, PRINT or EXECUTE statements, loops or case statements, and so on.

Parameter and variable values that are assigned but not used are also highlighted. In the following example, @i is assigned the value NULL, but this value is not used before @i is assigned the value 4.

To find unused variables and parameters:

  1. Open the source script in a SQL Server Management Studio query editor.
  2. If required, select the code that contains the parameters and variables that you want to check.
    If you do not select any code, all parameters and variables in the script are checked.
  3. On the SQL Refactor menu, click Find Unused Variables and Parameters.
    SQL Refactor underlines the unused parameters, variables, and values in the query editor.

Didn't find what you were looking for?