MS SQL Simple Scalar Function
CREATE FUNCTION dbo.GetProductCount ()
RETURNS INT
AS
BEGIN
DECLARE @Count INT = 0;
SELECT @Count=COUNT(1)
FROM Production.Product
RETURN @Count;
END
GO
-- EXECUTION
SELECT dbo.GetProductCount()
-- Parameterized Scalar Function
CREATE FUNCTION dbo.Divide (@A INT, @B INT)
RETURNS INT
AS
BEGIN
RETURN @A / @B
End
GO
-- EXECUTION
SELECT dbo.Divide (4,2)