Summary
User-defined functions expand the capabilities of SQL Server objects and open a world of flexibility within expressions and the SELECT statement.
The big ideas from this chapter follow:
- Scalar user-defined functions return a single value and must be deterministic.
- Inline table-valued user-defined functions are similar to views and return the results of a single SELECT statement.
- Multistatement, table-valued, user-defined functions use code to populate a table variable, which is then returned.
- The APPLY function can be used to pass data to an inline table-valued UDF or a multistatement, table-valued UDF from the outer query, similar to how a correlated subquery can receive data from the outer query.
T-SQL code can be packaged in stored procedures, user-defined functions, and triggers. The next chapter delves into stored procedures.