Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute stored procedure with table values as parameter

Tags:

tsql

I create own table type

CREATE TYPE [dbo].[ObjectsList] AS TABLE( [Id] [int] NOT NULL, PRIMARY KEY CLUSTERED  (    [Id] ASC )WITH (IGNORE_DUP_KEY = OFF) ) GO 

and when I want to pass this Type as parameter like

CREATE PROCEDURE [dbo].[GetData](@DataIds ObjectsList READONLY) 

how should I pass it in EXEC GetData ????

like image 480
netmajor Avatar asked Aug 31 '11 07:08

netmajor


People also ask

How do you execute a stored procedure with table valued parameters in SQL?

First a Table Variable of User Defined Table Type has to be created of the same schema as that of the Table Valued parameter. Then it is passed as Parameter to the Stored Procedure and the Stored Procedure is executed using the EXEC command in SQL Server.

Can we pass table variable as parameter in stored procedure?

You cannot pass table-valued parameters to CLR user-defined functions. Table-valued parameters can only be indexed to support UNIQUE or PRIMARY KEY constraints. SQL Server does not maintain statistics on table-valued parameters. Table-valued parameters are read-only in Transact-SQL code.


1 Answers

Look at this

You can find an example

DECLARE @data ObjectList INSERT @data (Id) VALUES (1) EXEC GetData @data 
like image 180
luviktor Avatar answered Sep 22 '22 22:09

luviktor