They seem to be identical in some ways, but not available to the outside world. what are some differences?i think its the ability to use the UDF inline that makes it easier.If you had to perform the same calculation in a procedure, you'd have to return the value as an output parameter. not necessarily difficult but mnore coding.
heres an answer fromAdvanced SQL Server Stored Procedure Programming Chat
Q: (SRC): Are there inherent performance benefits to using Stored procedure vs. User Defined Functions?
A: There is no difference in performance. Because of the enforced prevention of side-effects in a UDF, only UDFs can be used in queries.
ofcors, UDFs have some limitations too( like you cannot use non-deterministic built-in functions..like getdate() .etc), which am assuming you are aware of.
hth|||To elaborate a bit, a UDF can also return tabular (in addition to scalar) data, and thus can be joined to.
While this might seem similar to a view, it has one substantila advantage: it can be parameterized! So for potentially enormous result sets, a UDF can improve efficiency enormously.|||You also have to be careful using UDFs in other queries cause you can end up calling the func for every row returned and that can be painful. Also there are a number of normal SQL statements you can't do in funcs.
No comments:
Post a Comment