I would like to debug a complex T-SQL script using SSMS 2012.
I can run the script in debug mode and place breakpoints, as well as step through my script, but I can\'t
Including a select statement in the code is the only way I know and can think of.
Having a 'configuration' table in the database allows adding debugging code permanently to the SP, which helps if you have to debug it often. You can leave code like "if ({select logging level in config table}) = {debug} then select '@variable at location 1' as [@variable at location 1], * from @variable order by {some useful order}".
With the way I include the variable name and possibly the location (if there are several places where you need to check) in both the result and the column name, it makes it easy to tell apart the variables in the output even when a particular table variable has no rows, and you did not expect that.