How to view data in table variables during debugging session in MS SQL Management Studio 2012?

后端 未结 4 806
借酒劲吻你
借酒劲吻你 2021-02-18 20:21

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

4条回答
  •  再見小時候
    2021-02-18 21:17

    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.

提交回复
热议问题