Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to return a table from stored procedure

Author  Topic 

shantanu88d
Starting Member

35 Posts

Posted - 2011-03-22 : 04:50:08
I want to return an entire table as an output of a stored procedure. Is it possible??
Please explain

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-03-22 : 05:40:20
You can use a table-valued function for this

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2011-03-22 : 05:45:32
What is your exact requirement to do this ?
Because it can be achived easily by putting code "SELECT * FROM <Your Table>" in stored procedure.

Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-03-22 : 07:01:10
Or you can use "insert-exec" as described here (as long as you don't want to nest them etc.) http://www.sommarskog.se/share_data.html
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2011-03-22 : 08:59:45
Does not make sense.The the SP will return a resultset if you are using a Select statement in the SP.


Create Procedure Test
as
Select * from TestTable


The o/p is going to be a resultset which is indirectly a logical table.

PBUH

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-03-22 : 13:28:55
Doesn't it seem insane in the first place to get an exact copy off all the data from a table?

What do you plan to do with it, and what front end are you using to make the call?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -