In this syntax:
1
2
3
4
5
6
CREATE FUNCTION [schema_name.]function_name (parameter_list)
RETURNS data_type AS
BEGIN
statements
RETURN value
END
Modifying a scalar function
1
2
3
4
5
6
1
2
3
4
5
6
1
DROP FUNCTION
CREATE OR ALTER
DROP FUNCTION [schema_name.]function_name;
CREATE OR ALTER FUNCTION [schema_name.]function_name (parameter_list)
RETURN data_type AS
BEGIN
statements
RETURN value
END
ALTER FUNCTION [schema_name.]function_name (parameter_list)
RETURN data_type AS
BEGIN
statements
RETURN value
END
Create Function
CREATE FUNCTION dbo.WeightScale -- create name function ( -- Add the parameters for the function here @WeightPlan1 int, @WeightPlan2 int, @WeightPlan3 int ) RETURNS int -- return type data AS BEGIN -- Declare the return variable here DECLARE @ResultVar int; -- result return data -- Add the T-SQL statements to compute the return value here SET @ResultVar = @WeightPlan1 + @WeightPlan2 + @WeightPlan3; -- Return the result of the function RETURN @ResultVar; END
Select Data
SELECT dbo.WeightScale(1,2,3) sumdata