Nullable parameters in SQL 2005 & SQL 2008 - Column, parameter, or variable #1: Cannot find data type Nullable`1

When writing CLR code for SQL you need to handle nulls. You can do this in two ways, either your data types are nullable or you configure your functions to always return null when a parameter is null.

The last only works for some objects and so understanding nullable types is essential.

If you are using SQL 2008 then you are fortunate enough to be able to use Nullable types. These are generic types that implement INullable on top of the base type, i.e. Nullable<int> or int?. This provides you with a variable that has two properties .HasValue and .Value. HasValue allows you to check if the parameter is NULL, and .value gives you the base type value. If you access .Value when the value is NULL you will get an error, so its essential to check HasValue.

If you are using SQL 2005 whilst the CLR integration is based on a version of the CLR that supports nullable types they had to have nullable types before the languages supported them. This means they implemented their own nullable types. Sql* data types are the types you use in SQL 2005. If you try using the nullable types you will get the error.

Column, parameter, or variable #1: Cannot find data type Nullable`1

If you get that error then you need to switch to the SqlInt, SqlVarchar etc. These types can be found in the System.Data.SqlTypes namespace.

Published 29 October 2010 10:22 by simonsabin

Comments

29 October 2010 10:50 by SimonS Blog on SQL Server Stuff

# Nullable parameters in SQL 2005 & SQL 2008 - Column, parameter, or variable #1: Cannot find data type Nullable`1

When writing CLR code for SQL you need to handle nulls. You can do this in two ways, either your data

# Twitter Trackbacks for Nullable parameters in SQL 2005 &amp; SQL 2008 - Column, parameter, or variable #1: Cannot find data type Nullable`1 - Simons SQL Blog [sqlblogcasts.com] on Topsy.com

Pingback from  Twitter Trackbacks for                 Nullable parameters in SQL 2005 &amp; SQL 2008 - Column, parameter, or variable #1: Cannot find data type Nullable`1 - Simons SQL Blog         [sqlblogcasts.com]        on Topsy.com