Assert parameters in a table-valued UDF

Posted by Clay Lenhart on Stack Overflow See other posts from Stack Overflow or by Clay Lenhart
Published on 2011-01-14T09:29:29Z Indexed on 2011/01/14 9:53 UTC
Read the original article Hit count: 352

Filed under:
|

Is there a way to create "asserts" on the parameters of a table-valued UDF.

I'd like to use a table-valued UDF for performance reasons, however I know that certain parameter combinations (like start and end dates that are more than a month apart) will cause performance issues on the server for all users.

End users query the database via Excel using UDFs. UDFs (and table-valued UDFs in particular) are useful when the data is too large for Excel. Users write simple SQL queries that categorizes the data into groups to reduce the number of rows. For example, the user may be interested in weekly aggregates rather than hourly ones. Users write a group by SELECT statement to reduce the rows by 24x7=168 times. I know I can write RAISERROR statements in multistatement UDFs, but table-valued UDFs are integrated in the query optimizer so these queries are more efficient with table-valued UDFs.

So, can I define assertions on the parameters passed to a table-valued UDF?

© Stack Overflow or respective owner

Related posts about tsql

Related posts about table-udf