3

在 Management Studio 中执行存储过程以获取结果集的数据类型时,是否有办法返回?我正在寻找类似于将表名传递给 sp_help 的功能

4

6 回答 6

1

但是,如果您通过 ADO、ADO.NET、ODBC 等调用存储过程,您确实可以查看类型:生成的记录集具有您正在寻找的类型信息。您真的仅限于 Management Studio 吗?

于 2008-08-28T19:36:47.747 回答
1

您最好的选择是将存储过程更改为函数。但这只有在您的环境允许时才有效。

于 2008-10-01T12:57:20.210 回答
0

如果不解析 syscomments 以查看它从哪里查询的内容,就不会想到任何简单的方法。如果您可以编辑 SP 以选择 XML,则可以将 XML_INFO 附加到查询以获取模式。

于 2008-08-28T19:32:58.767 回答
0

实际上,您可以在 SP 中执行此操作:

EXEC ('if exists (select * from sys.tables where name = ''tmp_TableName'') drop table tmp_TableName')

EXEC ('select * into tmp_TableName from MyTable')

-- Grab the column types from INFORMATION_SCHEMA here

EXEC ('if exists (select * from sys.tables where name = ''tmp_TableName'') drop table tmp_TableName')

虽然,我认为必须有更好的方法。

于 2008-10-01T02:44:56.187 回答
0

这不是最优雅的解决方案,但您可以使用 OPENROWSET 将存储的 proc 结果放入表中,然后使用 sp_help 获取它的描述。

例如

select * into tmp_Results 
from openrowset( 'SQLOLEDB.1'
               , 'Server=your_server_name;Trusted_Connection=yes;'
               , 'exec your_stored_proc')
exec sp_help 'tmp_Results'
drop table tmp_Results
于 2008-10-01T09:04:48.350 回答
-1

您总是可以使用一个独特的实际表格。这是一个kludge,但它是一个选项。但是,这在存储过程中不起作用。

if exists (select * from sys.tables where name = 'tmp_TableName')
    drop table tmp_TableName
go
select * into tmp_TableName from MyTable

--do some stuff

go
if exists (select * from sys.tables where name = 'tmp_TableName')
    drop table tmp_TableName
go
于 2008-09-15T17:43:19.320 回答