TRY_PARSE使函数非确定性

时间:2016-11-04 11:39:05

标签: sql-server

我想使计算列保持不变,但TRY_PARSE使我的函数不确定。我可以做点什么吗?有替代品吗?

CREATE FUNCTION [dbo].[F] 
(
    @input nvarchar(100)
)
RETURNS int
WITH SCHEMABINDING
AS
BEGIN
    return TRY_PARSE(@input as INT)
END


SELECT OBJECTPROPERTY(OBJECT_ID('[dbo].[F]'), 'IsDeterministic')

1 个答案:

答案 0 :(得分:1)

改为使用TRY_CONVERT

CREATE FUNCTION [dbo].[F] 
(
    @input nvarchar(100)
)
RETURNS int
WITH SCHEMABINDING
AS
BEGIN
    return TRY_CONVERT(INT,@input)
END


SELECT OBJECTPROPERTY(OBJECT_ID('[dbo].[F]'), 'IsDeterministic')