Click here to Skip to main content
15,888,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have to get stored procedure's result inside table valued function, can i achieve this in SQL Server 2005 ?

I have to do something like this, Please see code below :
SQL
CREATE FUNCTION Test()
RETURNS TABLE AS
RETURN 
(
	exec 'sp_who'
)

Thanks in advanced,
Rahul
Posted
Updated 21-Nov-19 10:12am
v2

Use this query to select data from a stored procedure :

SQL
sp_configure 'Show Advanced Options', 1
GO
RECONFIGURE
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
GO

SELECT * FROM OPENROWSET('SQLNCLI', 'Server=servername\SQLEXPRESS;Trusted_Connection=yes;',
     'EXEC dbname.dbo.sp_who')


You can even send parameters to that stored procedure.

Hope it helps.
 
Share this answer
 
No, its not possible.
You have to rewrite your procedure to user defined function.
More help[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900