1

I'm currently debugging an Ms SQL Function (SQL 2008).

In this function, I have a variable declared this way:

DECLARE @TempTable TABLE ( Id INT UNIQUE );

Then, I insert some records using an insert into...select statement.

When debugging, I would like to see the records in this table.

Is there a way to do this?

Thanks

vIceBerg
  • 4,197
  • 5
  • 40
  • 53
  • Seems like a duplicate of http://stackoverflow.com/questions/1900857/how-to-see-the-values-of-a-table-variable-at-debug-time-in-t-sql – zarzych May 03 '13 at 07:45

2 Answers2

1

I built a procedure which will display the content of a temp table from another database connection. (which is not possible with normal queries). Note that it uses DBCC PAGE & the default trace to access the data so only use it for debugging purposes.

You can use it by putting a breakpoint in your code, opening a second connection and calling:

exec sp_select 'tempdb..#mytable'

Filip De Vos
  • 11,568
  • 1
  • 48
  • 60
0

One possible solution, that may not be the best, is to:

  • Create a permanent table that is the same as the temporary table
  • Modify the function so that it dumps the data from the temporary table into the permanent table at the point where the temp table contains the data you're interested in seeing

When the function ends, open up the new permanent table and you'll have a copy of the temporary table's state.

This requires that you have permission to create new tables and modify the function.

Ant
  • 4,890
  • 1
  • 31
  • 42
  • I was afraid of that. I really thought that I could see the table`s content within the debugger. I'll try your way. – vIceBerg Mar 16 '10 at 14:58