SQL CLR and nullable datetime parameter

Posted by toluca70 on Stack Overflow See other posts from Stack Overflow or by toluca70
Published on 2010-05-27T15:39:41Z Indexed on 2010/05/27 15:41 UTC
Read the original article Hit count: 240

Filed under:
|
|
|
|

I'm trying to write a SQLCLR function that takes a DateTime2 as input and returns another DateTime2. Based on this post I altered the parameter to be the C# type DateTime giving me the level of precision I require. However because the input can be null I would like it to be DateTime?; the return type as well.

using System;
using Microsoft.SqlServer.Server;

namespace SqlServer.Functions {
    public class UserDefinedFunctions {
        [SqlFunction(DataAccess = DataAccessKind.None)]
        public static DateTime? GetLocalTimeFromGMT(DateTime? dateTime) {
            if (dateTime.HasValue)
                return DateTime.SpecifyKind(dateTime.Value, DateTimeKind.Utc).ToLocalTime();
            else
                return (DateTime?)null;
        }
    }
}

The problem is I get the following error when I try to deploy:

Error 1 Cannot find the type 'Nullable`1', because it does not exist or you do not have permission. SqlServer.Functions

I'm using Sql Server 2008 and Visual Studio 2008.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET