netmajor
netmajor

Reputation: 6585

Execute stored procedure with table values as parameter

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 ????

Upvotes: 35

Views: 58834

Answers (2)

Zach Smith
Zach Smith

Reputation: 8961

To populate @data by using a SELECT statement:

DECLARE @data ObjectList

INSERT @data (Id)
SELECT
  Id
FROM
  <someDB>.<someSchema>.<someTable>
  JOIN ... etc 
WHERE
  ... etc

EXEC GetData @data

Upvotes: 1

luviktor
luviktor

Reputation: 2270

Look at this

You can find an example

DECLARE @data ObjectList
INSERT @data (Id) VALUES (1)
EXEC GetData @data

Upvotes: 67

Related Questions