Reputation: 65
I have a large script that I need to debug to catch an error. There is a table in the script declared as a variable. Some t-sql makes an insert into that table. I would like to select from the table while in the debug mode. I have the "locals" window opened on the screen but I cannot see the contents of the table there, just the variable itself, neither can I select from the temporary table-variable when the code execution stops at the desired breakpoint.
Is there a way I can query the table in the debug mode? Thanks!
Upvotes: 0
Views: 270
Reputation: 8101
For the purposes of debugging, you could replace the table variable (@tableName) with a global temporary table (##tableName).
Table variables and local temporary tables (#tableName) only exist within the session where they're defined, so can only be queried within that session. Global temporary tables can be accessed from other sessions and will persist until all connections to them are dropped, so you'll be able to check results from a different SSMS window as the script is executing in it's window.
You'll want to comment out the table variable definition, then add the CREATE TABLE ##...
statement. After that, Find & Replace should get your script ready (and put it back when you're done).
Here's the documentation on Temporary Tables.
Upvotes: 1