使用返回Datetime结果的UDF SQL CLR获取错误

时间:2014-03-20 10:42:17

标签: c# sql sql-server clr sqlclr

我定义了两个函数

1)返回String

  [Microsoft.SqlServer.Server.SqlFunction]
public static SqlString TestScalarFunction()
{
    return new SqlString ("RJ");
}

2)返回日期时间

[Microsoft.SqlServer.Server.SqlFunction]
public static SqlDateTime ScalarUDF()
{
    string zoneId = "Singapore Standard Time";
    TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(zoneId);
    SqlDateTime result = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tzi);

    return result;
}

将UDF创建为::

CREATE FUNCTION [dbo].TestScalarFunction()
RETURNS nvarchar(100)
WITH EXECUTE AS CALLER
AS
EXTERNAL NAME UDF_Blog.UserDefinedFunctions.TestScalarFunction;
GO

CREATE FUNCTION [dbo].ScalarUDF()
RETURNS datetime
WITH EXECUTE AS CALLER
AS
EXTERNAL NAME UDF_Blog.UserDefinedFunctions.ScalarUDF;
GO

I am Getting Problem with only UDF(ScalarUDF) which returns Datetime in its result.

我使用查询作为::

select dbo.TestScalarFunction()  --this successfully gives Result

select dbo.ScalarUDF()   --this gives the Error

0 个答案:

没有答案