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.
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.
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.
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.
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 :)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With