Find definitions and references of SQL Command Variables in a SQL script

Home / Find definitions and references of SQL Command Variables in a SQL script

(This is a C# LinqPad script)

Using setvar in T-SQL

Finds the SQL Command Variable definitions in a SQL script and parses their names and values.
Finds the SQL Command Variable references and parses their names.
Determines which references have no definitions.
Determines which definitions have no references.

The definition names and reference names are case insensitive.
A definition is in the form of :setvar name “value”
A reference is in the form of $(name)