我正在尝试编写一个 SQLCLR 函数,该函数将 DateTime2 作为输入并返回另一个 DateTime2。根据这篇文章,我将参数更改为 C# 类型 DateTime,从而达到我需要的精度水平。但是,因为输入可以是 null 我希望它是 DateTime?; 返回类型也是如此。
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;
}
}
}
问题是我在尝试部署时收到以下错误:
错误 1 找不到类型“Nullable`1”,因为它不存在或者您没有权限。SqlServer.Functions
我正在使用 Sql Server 2008 和 Visual Studio 2008。