Lalita
Lalita

Reputation: 163

Table valued parameter error parameter or variable has an invalid datatype

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

Errors what am getting:Must declare the table variable @FactIds Please help me out of this issues.

Upvotes: 0

Views: 4288

Answers (1)

xanatos
xanatos

Reputation: 111830

It's

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

see the ending )? It creates a type. You use it only once, and the type "remains" (like a table or a view)

and you must execute it BEFORE doing the declare

Or you can put a GO in-between:

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

GO

DECLARE @FactIds As [dbo].[tblFactIds]

so that the CREATE TYPE is executed.

Upvotes: 1

Related Questions