Introduction
Scalar functions are user-defined functions that return a single value. They are often used to perform calculations or transformations on data.
Syntax
CREATE FUNCTION function_name (parameter1, parameter2, ...)
RETURNS data_type
AS
BEGIN
-- Function body
RETURN expression;
END;
Examples
CREATE FUNCTION dbo.Square( @Number INT )
RETURNS INT
AS
BEGIN
RETURN @Number * @Number;
END;