表值参数错误参数或变量具有无效的数据类型

时间:2015-03-13 12:22:56

标签: sql-server sql-server-2008 c#-4.0 table-valued-parameters

//Table valued parameter creation
CREATE TYPE [dbo].[tblFactIds] AS TABLE(
[FactId] [int] NULL
//using TVP in SP,just declaring a var of type TVP which i created
DECLARE @FactIds As tblFactIds;//error: parameter or variable has an invalid datatype //tried by adding READONLY also
INSERT INTO @FactIds (FactId)
 SELECT * FROM Sampletable

错误:必须声明表变量@FactIds 请帮我解决这个问题。

1 个答案:

答案 0 :(得分:1)

它的

CREATE TYPE [dbo].[tblFactIds] AS TABLE
(
    [FactId] [int] NULL
)

查看结尾)?它创建了一种类型。你只使用它一次,类型"仍然是" (如桌子或视图)

并且必须在执行声明

之前执行它

或者您可以将GO置于其间:

CREATE TYPE [dbo].[tblFactIds] AS TABLE
(
    [FactId] [int] NULL
)

GO

DECLARE @FactIds As [dbo].[tblFactIds]

以便执行CREATE TYPE