2011-06-02 43 views
6

Sql Server Management Studio(2008)有什么方法可以查看查询结果中每个字段的数据类型吗?在SQL Server Management Studio中查看结果集的模式

在这种情况下,我正在运行一个返回结果集的存储过程,我想知道nvarchar列的长度和小数的精度。

过去,我创建了一个视图,它包含存储过程中的基础查询,然后查看列列表,但是在这种情况下,过程中的查询太复杂了。

任何想法?

回答

6

快速和脏的片段,要求结果集中的所有字段都被命名或别名;

select * into #T 
from 
    openrowset('SQLNCLI', 'Server=.;Trusted_Connection=yes;', 'exec thedb.dbo.sp_whatever') 
exec('use tempdb exec sp_columns #T drop table #T') 
+0

相同的方法和死热 - 对不起,我不能标记两个答案。指向服务器的亚历克斯K =。而sp_columns比sp_help更具体。非常感谢。 – 2011-06-02 16:20:29

+1

必须启用“Ad-hoc分布式查询”才能使用此功能: sp_configure'show advanced options',1; RECONFIGURE; sp_configure'Ad Hoc Distributed Queries',1; RECONFIGURE; GO – 2013-04-03 17:47:07

4

最好的办法可能是使用OPENROWSET将过程的输出存储到表中,然后检查该表。例如:

SELECT * INTO YourHoldingTable 
    FROM OPENROWSET('SQLNCLI', 'Server=YourServerName;Trusted_Connection=yes;', 'EXEC YourDatabase.YourSchema.YourProcedureName') 
GO 

sp_help 'YourHoldingTable' 
GO 

DROP TABLE 'YourHoldingTable' 
GO 
相关问题