Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL problem with error "Invalid data type"

Using SQL 2008

So I created a User Defined type:

CREATE TYPE dbo.ServiceType AS TABLE ( [TO_ZONE] varchar(30) NOT NULL, [FROM_ZONE] varchar(30) NOT NULL, [RATE] decimal(14,2) NOT NULL, [SERVICE_TYPE] varchar(255) NOT NULL ); 

And when I try to use it I get the error "parameter or variable @variableName has an invalid data type"

ALTER PROCEDURE [dbo].[ImportServiceTypeRates]  (@ServiceTypes dbo.ServiceType)  --I have tried it without the "dbo." as well 

Update

So I added "READONLY" to my variable declaration

@ServiceTypes dbo.ServiceType READONLY 

And I now get the error "The parameter @Servicetype cannot be declared READONLY because it is not a table-valued parameter" ?WHAT?

I thought the "CREATE TYPE ServiceType as TABLE" was what declared it such???

I also have showing in Types\User-Defined Table Types\dbo.ServiceType

like image 413
pghtech Avatar asked Feb 17 '11 05:02

pghtech


People also ask

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.

Which is not valid SQL Server data type?

The data type varchar is not one of the supported data types on SQL Server CE.

Which is the valid datatype in SQL?

Because Characters, Numeric, and Float are all valid SQL types. If you are willing to learn SQL and wish to get certified in SQL, have a look at the SQL certification course from Intellipaat.


2 Answers

I know this is an old post but since I encountered the same issue and was able to solve it, thought of sharing it. This is an IntelliSense cache issue and could be solved by pressing ctrl+shift+R (shortcut for Edit -> IntelliSense -> Refresh Local Cache)

like image 51
sam Avatar answered Sep 23 '22 04:09

sam


You must declare your table-valued parameter as READONLY.

ALTER PROCEDURE [dbo].[ImportServiceTypeRates]        @ServiceTypes dbo.ServiceType READONLY  AS    --your proc 

Even though SQL Server forces your table-valued parameter to be read-only, you must also explicitly declare it so in the stored procedure parameter list.

http://msdn.microsoft.com/en-us/library/bb675163.aspx

like image 20
p.campbell Avatar answered Sep 19 '22 04:09

p.campbell