I'm using SQL Server 2005.
我正在使用SQL Server 2005。
My stored procedure returns 100 columns and has 10 pages.
我的存储过程返回100列,有10页。
I'd only need to return 5 of the columns and don't want to duplicate the 10 pages of the stored procedure by creating a new stored procedure.
我只需要返回5列,并且不希望通过创建新的存储过程来复制存储过程的10个页面。
I'd like to avoid defining a new table variable with 100 columns! and I'd like to avoid defining a LinkServer and use OPENROWSET because the server name, etc shouldn't be hardcoded.
我想避免使用100列定义新的表变量!我想避免定义LinkServer并使用OPENROWSET,因为服务器名称等不应该是硬编码的。
Is there any easier/better way?
有没有更简单/更好的方法?
If so, how to write it? The below code doesn't work:
如果是这样,怎么写呢?以下代码不起作用:
select ID, Title, (the remaining 3 columns)
from exec dbo.sp_myName
1 个解决方案
#1
1
You could create a temp table with all the columns that are returned by the stored procedure, and then use:
您可以使用存储过程返回的所有列创建临时表,然后使用:
Insert Into #TempTable
Exec dbo.sp_myName
Select ID, Title,...
From #TempTable
#1
1
You could create a temp table with all the columns that are returned by the stored procedure, and then use:
您可以使用存储过程返回的所有列创建临时表,然后使用:
Insert Into #TempTable
Exec dbo.sp_myName
Select ID, Title,...
From #TempTable