2011-08-31 77 views
16

我創建自己的表型執行存儲過程的表值參數

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

,當我想通過這種類型的參數一樣

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

我應該如何通過它在 EXEC的GetData ????

回答

29

Look at this

你可以找到一個例子

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

要使用SELECT語句填充@data:

DECLARE @data ObjectList 

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

EXEC GetData @data