all groups > sql server programming > october 2004 >
You're in the

sql server programming

group:

Passing table-type variables to SP?


Re: Passing table-type variables to SP? Louis Davidson
10/17/2004 6:02:18 PM
sql server programming:
Give us some more information about why you want to do this(, and why you
felt you needed to post this to multiple newsgroups)

You cannot pass a table variable as a parameter, but there are a few methods
to pass formatted strings as tables, if your needs are pretty simple. The
best one is probably to use XML and OPENXML. Just look up OPENXML in the
docs.

--
----------------------------------------------------------------------------
Louis Davidson - drsql@hotmail.com
SQL Server MVP

Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)

[quoted text, click to view]

Passing table-type variables to SP? Agoston Bejo
10/17/2004 8:00:02 PM
Sorry about posting twice, but I had some trouble with setting the date on
this machine... :)

I would like to write a stored procedure that takes a table (i.e. table
variable) as its parameter.

E.g.:
DECLARE @mytable = TABLE(ID INT, NAME VARCHAR(50))
SP_MYPROC @mytable

What should SP_MYPROC's signature look like? I can't seem to be able to find
anything about this in the documenation.
I guess it would look something like this:

ALTER PROCEDURE SP_MYPROC
(@t TABLE)

or

ALTER PROCEDURE SP_MYPROC
(@t TABLE(ID INT, NAME VARCHAR(50)))

Actually, how big is the freedom when taking such a parameter? Is it enough
to use the first version and treat the table whatever way I would like to?
E.g. not assuming that the 'NAME' column is a VARCHAR(50), but taking
any tables the second column of which is of type VARCHAR of any size.



Re: Passing table-type variables to SP? John Bell
10/17/2004 8:45:15 PM
Hi

You can not pass a table data type to a stored procedure. You may want to
use temporary tables instead.

From Books online "Create procedure" topic
CREATE PROC [ EDURE ] [ owner. ] procedure_name [ ; number ]
[ { @parameter data_type }
[ VARYING ] [ = default ] [ OUTPUT ]
] [ ,...n ]

[ WITH
{ RECOMPILE | ENCRYPTION | RECOMPILE , ENCRYPTION } ]

[ FOR REPLICATION ]

AS sql_statement [ ...n ]

data_type

Is the parameter data type. All data types, except the table data type, can
be used as a parameter for a stored procedure. However, the cursor data type
can be used only on OUTPUT parameters. When you specify a data type of
cursor, the VARYING and OUTPUT keywords must also be specified. For more
information about SQL Server - supplied data types and their syntax, see
Data Types.

John

[quoted text, click to view]

Re: Passing table-type variables to SP? Roji. P. Thomas
10/18/2004 11:15:34 AM
You cannot pass a table variable from one sp to another.

This article discuss the options to share data between procs.

http://www.sommarskog.se/share_data.html


--
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com


[quoted text, click to view]

AddThis Social Bookmark Button