How to see the values of a table variable at debug

2019-01-08 03:53发布

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

9条回答
老娘就宠你
2楼-- · 2019-01-08 04:08

In the Stored Procedure create a global temporary table ##temptable and write an insert query within your stored procedure which inserts the data in your table into this temporary table.

Once this is done you can check the content of the temporary table by opening a new query window. Just use "select * from ##temptable"

查看更多
做个烂人
3楼-- · 2019-01-08 04:08

I have come to the conclusion that this is not possible without any plugins.

查看更多
混吃等死
4楼-- · 2019-01-08 04:14
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

查看更多
在下西门庆
5楼-- · 2019-01-08 04:20

This project https://github.com/FilipDeVos/sp_select has a stored procedure sp_select which allows for selecting from a temp table.

Usage:

exec sp_select 'tempDb..#myTempTable'

While debugging a stored procedure you can open a new tab and run this command to see the contents of the temp table.

查看更多
甜甜的少女心
6楼-- · 2019-01-08 04:21

Just use the select query to display the table varialble, where ever you want to check.

http://www.simple-talk.com/sql/learn-sql-server/management-studio-improvements-in-sql-server-2008/

查看更多
成全新的幸福
7楼-- · 2019-01-08 04:22

SQL Server Profiler 2014 lists the content of table value parameter. Might work in previous versions too. Enable SP:Starting or RPC:Completed event in Stored Procedures group and TextData column and when you click on entry in log you'll have the insert statements for table variable. You can then copy the text and run in Management Studio.

Sample output:

declare @p1 dbo.TableType
insert into @p1 values(N'A',N'B')
insert into @p1 values(N'C',N'D')

exec uspWhatever @PARAM=@p1
查看更多
登录 后发表回答