Scalar Functions : Utility function « Procedure Function « SQL Server / T-SQL Tutorial






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>








21.6.Utility function
21.6.1.Scalar Functions
21.6.2.Format a date
21.6.3.linear_max() Scalar Function
21.6.4.The linear_min Scalar Function
21.6.5.Changing Character Values to Proper Case with user-defined functions
21.6.6.if an int odd