User defined function in SQL Server
Like functions in programming languages, SQL Server user-defined functions are routines that accept parameters, perform an action, such as a complex calculation, and return the result of that action as a value. The return value can either be a single scalar value or a result set.
Why use user-defined functions (UDFs)?
User-defined functions
can be modified independently of the program source code.
Types of functions
RETURNS
clause. For an inline scalar function,
the returned scalar value is the result of a single statement. For a multistatement scalar function,
the function body can contain a series of Transact-SQL statements that return the single value.
The return type can be any data type except text
, ntext
, image
, cursor
, and timestamp
.
SELECT
statement.