开发者

How to silence errors inside a UDF?

I need to write a UDF that would try to cast a varchar to a bigint and re开发者_StackOverflow社区turn either that bigint or zero if failed. The problem is - I can't find a way to silence casting error when the string is not a valid number. TRY CATCH doesnt work inside functions and I don't know what else to do.


Try this:

Create Function dbo.Convert2BigInt(@Data VarChar(100))
Returns BigInt
As 
Begin
    Return(Case When IsNumeric(@Data + '.0e0') = 1 
                Then Convert(BigInt, @Data)
                Else Convert(BigInt, 0)
                End)
End
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜