A scalar function accepts any number of parameters and returns one value : Scalar Functions « Store Procedure Function « SQL Server / T-SQL






A scalar function accepts any number of parameters and returns one value


30> -- Scalar Functions
31>
32> -- A scalar function accepts any number of parameters and returns one value.
33>
34> CREATE FUNCTION fnGetAge (@BirthDate DateTime, @Today DateTime)
35>   RETURNS Int
36> AS
37>   BEGIN
38>      RETURN DateDiff(day, @BirthDate, @Today) / 365.25
39>   END
40> GO
1>
2> SELECT dbo.fnGetAge('1/4/1962', GetDate())
3> GO

-----------
         44

(1 rows affected)
1>
2> drop function fnGetAge
3> GO
1>
           
       








Related examples in the same category