SQL CLR and nullable datetime parameter

I am trying to write a SQLCLR function that takes DateTime2 as input and returns another DateTime2. Based on this post, I changed the parameter as a C # type of DateTime type, giving me the necessary level of accuracy. However, since the input may be null, I would like it to be a DateTime ?; return type also.

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 that when I try to deploy, I get the following error:

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

I am using Sql Server 2008 and Visual Studio 2008.

+3
1

, Visual Studio 2008 SQLCLR , SQL Server 2008, Nullable Types. Connect item , , Visual Studio 2010.

, Connect, Visual Studio, System.Core System.Xml.Linq SQLCLR, . .

+1

Source: https://habr.com/ru/post/1747393/


All Articles