[英]SQL CLR and nullable datetime parameter
我正在嘗試編寫一個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。
遺憾的是,Visual Studio 2008不支持部署SQLCLR功能,其中包括SQL Server 2008中添加的許多新功能,包括Nullable Types。 您可以在此問題上看到針對Visual Studio 2010修復的Connect項目 Bob Beauchemin。
Connect項中列出了一種解決方法,它向Visual Studio指示它可以使用SQLCLR中的System.Core和System.Xml.Linq程序集,它們應該適合您。 否則,您可以手動將該功能部署到數據庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.