Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
Development
»
Table variable as Output Parameter
19 posts, Page 1 of 2
1
2
»»
Table variable as Output Parameter
Rate Topic
Display Mode
Topic Options
Author
Message
aziz.kapadia
aziz.kapadia
Posted Wednesday, December 31, 2008 2:58 AM
SSC Rookie
Group: General Forum Members
Last Login: Sunday, March 11, 2012 11:11 AM
Points: 31,
Visits: 29
Can I declare table variable as output parameter in stored procedure?
Post #627916
ChiragNS
ChiragNS
Posted Wednesday, December 31, 2008 3:21 AM
SSCrazy
Group: General Forum Members
Last Login: Wednesday, April 24, 2013 5:02 AM
Points: 2,365,
Visits: 1,825
No not in a stored proc in SQL 2005. You can use XML variable instead or use a table valued function if possible in your case.
"Keep Trying"
Post #627924
Adi Cohn-120898
Adi Cohn-120898
Posted Wednesday, December 31, 2008 4:26 AM
SSCrazy
Group: General Forum Members
Last Login: Yesterday @ 10:47 PM
Points: 2,023,
Visits: 4,948
Another option might be to work with temporary table, but that depends on what you are trying to do and how you are doing it.
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #627947
aziz.kapadia
aziz.kapadia
Posted Wednesday, December 31, 2008 4:32 AM
SSC Rookie
Group: General Forum Members
Last Login: Sunday, March 11, 2012 11:11 AM
Points: 31,
Visits: 29
I want to take output as a table and want to use it in other stored procedure.
Post #627950
Grant Fritchey
Grant Fritchey
Posted Wednesday, December 31, 2008 6:03 AM
SSChampion
Group: General Forum Members
Last Login: Yesterday @ 9:49 AM
Points: 13,436,
Visits: 25,281
I think you can do that in 2008, not that it helps you in 2005.
----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #627989
Adi Cohn-120898
Adi Cohn-120898
Posted Wednesday, December 31, 2008 6:39 AM
SSCrazy
Group: General Forum Members
Last Login: Yesterday @ 10:47 PM
Points: 2,023,
Visits: 4,948
Grant Fritchey (12/31/2008)
I think you can do that in 2008, not that it helps you in 2005.
Table valued parameters exist in SQL Server 2008, but it can only be input read only parameters. Since the original poster wanted an output parameter, he won't be able to use the table valued parameters even with SQL Server 2008
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #628014
Grant Fritchey
Grant Fritchey
Posted Wednesday, December 31, 2008 6:57 AM
SSChampion
Group: General Forum Members
Last Login: Yesterday @ 9:49 AM
Points: 13,436,
Visits: 25,281
Thanks for the correction. I wasn't sure and I haven't really looked at the table valued parameters yet. I should have kept my mouth shut.
----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #628030
Seggerman-675349
Seggerman-675349
Posted Thursday, January 01, 2009 7:11 AM
SSC Veteran
Group: General Forum Members
Last Login: Friday, July 08, 2011 2:11 PM
Points: 239,
Visits: 509
Check out table functions as an option, depending of course on what you are trying to do.
Post #628428
dhaval.samaranayeke
dhaval.samaranayeke
Posted Friday, January 02, 2009 6:41 AM
Grasshopper
Group: General Forum Members
Last Login: Tuesday, October 06, 2009 3:17 AM
Points: 18,
Visits: 18
If you want to use a table for a stored procedure, you can create a function which will return a table and then use this function in your stored procedure. Something like this
CREATE FUNCTION dbo.fnFunction_Name
(
@Param1 VARCHAR(8000),
@Param2 VARCHAR(8000)
)
RETURNS @Results TABLE (intRowId INTEGER IDENTITY(1,1) , Items VARCHAR(8000))
AS
BEGIN
//Your body here.
//You can insert the resultset in the table variable @Results in the body.
//At the end do not forget to return the variable
Return
END
You can use this function directly as a table i.e.
SELECT * FROM dbo.fnFunction_Name(@Param1, @Param2)
I hope this will be of some help to you.
Post #628771
Matt Miller (#4)
Matt Miller (#4)
Posted Friday, January 02, 2009 12:42 PM
SSCertifiable
Group: General Forum Members
Last Login: 2 days ago @ 8:45 PM
Points: 7,002,
Visits: 13,999
If your stored proc doesn't lend itself to being re-written as a function, you can always look at using a self-referenced linked server set up. Meaning - set up the DB instance as a linked server to itself, so that you can use OPENQUERY (which would allow you to use the recordset from a stored proc in the same places as a table).
As in - the following would work (assuming the stored proc has a SELECT statement outputtting data)
select * from OPENQUERY(mySelfLink, 'Exec myDb.dbo.MyStoredProc @sqlParams') q
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Post #629038
« Prev Topic
|
Next Topic »
19 posts, Page 1 of 2
1
2
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.