Invalid data type while using user defined table type
Asked By: Hot Cool Stud
Originally Asked On: 2014-01-02 11:36:38
Asked Via: stackoverflow
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 wired i notice right now when i put
,
after@dt [dbo].[ApproveAddsIds] READONLY
above error removed and now error is onAS
Saying expecting variables. When i write code for variables old error continued. I think it might help.
He received 3 answers
eventually accepting:
‘s answer to
Invalid data type while using user defined table type
The answer with the highest score with 4 points was:
Anya Hope’s answer to
Invalid data type while using user defined table type
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 the selected answer did not help you out, the other answers might!
All Answers For: Invalid data type while using user defined table type
Radhamani Muthusamy’s answer to
Invalid data type while using user defined table type
The same code works for me too. But there is no statements between
BEGIN
andEND
.Try by adding some statements like thisSET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO create PROCEDURE [dbo].[GetTopTopic]( @dt [dbo].[ApproveAddsIds] READONLY ) AS BEGIN --Write some statements here print 'hi' END
Anya Hope’s answer to
Invalid data type while using user defined table type
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.
Charlie Joynt’s answer to
Invalid data type while using user defined table type
I have had this same issue after creating a new new user-defined table type (UDTT) in one query window and then trying to create a new stored procedure in another. As per another answer to this question, I solved it by restarting SQL Server Management Studio. However it annoyed me that I had to restart the application as I had plenty of other work open/in-progress.
In my case I had noticed that IntelliSense in SSMS had underlined the name of my UDTT with a red squiggly line. I found the following advice…
By far the most common scenario is that your local, in-memory cache is
stale. This can be more prevalent if you switch databases often using
the USE command, or if the database is changing in other query windows
or by other users. You can refresh the cache by pressing Ctrl+Shift+R
or by selecting the menu option Edit > IntelliSense > Refresh Local
Cache. As above, you may need to wait for the cache to fully load,
depending on the size of your metadata and other resources involved…… on the following web page …
The advice is echoed on MSDN, with another bit of advice here:
https://msdn.microsoft.com/en-us/library/ms173434.aspx
IntelliSense functionality does not cover database objects created by
another connection after your editor window connected to the database.I cannot be sure whether refreshing the IntelliSense cache would have any effect on errors thrown when actually trying to create the Stored Procedure, but since the restart of SMSS solved the problem with no other changes to the script, a caching problem does sound about right.
Of course, you should really check out the original question.
The post Invalid data type while using user defined table type [ANSWERED] appeared first on Tech ABC to XYZ.