Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid data type while using user defined table type

I'm new to table-valued parameter in SQL Server 2008. I tried to make user-defined table with query

USE [DB_user]
GO
CREATE TYPE [dbo].[ApproveAddsIds] AS TABLE(
    [Ids] [bigint] NULL
)
GO 

When I tried to use the table type in stored procedure

USE [DB_user]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create  PROCEDURE [dbo].[GetTopTopic]
    @dt  [dbo].[ApproveAddsIds] READONLY      
AS
BEGIN

END

I got two errors_

@dt has an invalid data type
Parameter @dt cannot be declared read only since it is not table-valued parameter.

So I tried to figure out reason behind this as first query is executed successfully I thought its because of permissions and so tried

GRANT EXEC ON TYPE::[schema].[typename] TO [User]
GO

But error continues don't know whats wrong with this.

Something weird I noticed right now when I put , after @dt [dbo].[ApproveAddsIds] READONLY above error removed and now error is on AS Saying expecting variables. When I write code for variables old error continued. I think it might help.

like image 736
Hot Cool Stud Avatar asked Jan 02 '14 11:01

Hot Cool Stud


People also ask

What is a user-defined table type?

User-defined tables represent tabular information. They are used as parameters when you pass tabular data into stored procedures or user-defined functions. User-defined tables cannot be used to represent columns in a database table.

What is invalid data type in SQL?

Invalid SQL data type errors occur with SPL int64 data types and Oracle databases. If you have data that is an INTEGER data type in a table in an Oracle database, and you attempt to send or receive data by using an int64 data type in an SPL application, invalid data type errors can occur.

How do you change the user-defined table type?

The user-defined table type definition cannot be modified after it is created. You will need to drop any procedures or functions which depend on the type; drop the type; create the type with the new definition; and finally re-create the dependant procedures / functions.


2 Answers

I know I am late to the party but actually what you see is the problem with SSMS Intellisense and you can easily resolve it without restarting whole SSMS. Just press CTRL-SHIFT-R. Wait a few moments and problem is resolved :)

like image 170
ingbabic Avatar answered Sep 20 '22 17:09

ingbabic


I had this exact problem happening to me. I simply made sure I had saved everything I needed in SQL Server and restarted the SQL Server Management Studio.

Once restarted, the errors no longer appeared. I am using SQL Server 2012 but I don't see why this shouldn't also work with 2008.

like image 42
Anya Hope Avatar answered Sep 19 '22 17:09

Anya Hope