Error Handling in User Defined Functions

前端 未结 2 2121
旧时难觅i
旧时难觅i 2021-01-04 19:34

I want to write a non-CLR user-defined function in SQL Server 2005. This function takes an input string and returns an output string. If the input string is invalid, then I

2条回答
  •  南笙
    南笙 (楼主)
    2021-01-04 20:27

    It seems that SQL Server UDF's are a bit limited in this (and many other) way.

    You really can't do a whole lot about it - that's (for now) just the way it is. Either you can define your UDF so that you can signal back an error condition by means of its return value (e.g. returning NULL in case of an error), or then you would almost have to resort to writing a stored procedure instead, which can have a lot more error handling and allows RAISERROR and so forth.

    So either design your UDF to not require specific signaling of error conditions, or then you have to re-architect your approach to use stored procedures (which can have multiple OUTPUT parameters and thus can also return error code along with your data payload, if you need that), or managed CLR code for your UDF's.

    Sorry I don't have a better idea - for now, I'm afraid, those are your options - take your pick.

    Marc

提交回复
热议问题