篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql MS SQL简单标量函数相关的知识,希望对你有一定的参考价值。
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)