A scalar function accepts any number of parameters and returns one value.
Input parameters are declared within parentheses followed by the return value declaration.
All statements must be enclosed in a BEGIN. . . END block.
8>
9> CREATE FUNCTION fnGetAge (@BirthDate DateTime, @Today DateTime)
10> RETURNS Int
11> AS
12> BEGIN
13> RETURN DateDiff(day, @BirthDate, @Today) / 365.25
14> END
15> GO
1>
2>
3> drop function fnGetAge;
4> GO
1>
|