How to see the values of a table variable at debug time in T-SQL?

Faiz picture Faiz · Dec 14, 2009 · Viewed 102.7k times · Source

Can we see the values (rows and cells) in a table valued variable in SQL Server Management Studio (SSMS) during debug time? If yes, how?

enter image description here

Answer

kirby picture kirby · Jul 19, 2011
DECLARE @v XML = (SELECT * FROM <tablename> FOR XML AUTO)

Insert the above statement at the point where you want to view the table's contents. The table's contents will be rendered as XML in the locals window, or you can add @v to the watches window.

enter image description here