-- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the function. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION SharedRatioAiAj ( -- Add the parameters for the function here @attribute1 varchar(50), @attribute2 varchar(50) ) RETURNS REAL AS BEGIN DECLARE @SharedRatio INT; DECLARE @max INT; DECLARE @sum INT; DECLARE @distinctAi INT; DECLARE @distinctAj INT; EXEC @distinctAi = DistinctAi @attribute1; EXEC @distinctAj = DistinctAi @attribute2; IF @distinctAi >= @distinctAj SET @max = @distinctAi ; IF @distinctAi <= @distinctAj SET @max = @distinctAj ; EXEC @sum = DistinctAiAj @attribute1, @attribute2; SET @SharedRatio = (CAST(@sum AS REAL))/(CAST(@max AS REAL)); RETURN @SharedRatio; END; GO