-- ================================================ -- Template generated from Template Explorer using: -- Create Procedure (New Menu).SQL -- -- 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 procedure. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION DistinctMAXAi ( --@max INT=0 ) RETURNS INT AS BEGIN DECLARE @max INT; DECLARE attributes CURSOR FOR SELECT distinct attribute FROM CorrelationAttributes DECLARE @att VARCHAR(50); DECLARE @attValue INT; DECLARE @attValueC VARCHAR(50); OPEN attributes FETCH NEXT FROM attributes into @att; SELECT @attValueC = TableDistinctAi FROM TableDistinctAi(@att); --PRINT @attValueC; SET @max = CAST(@attValueC AS INT); WHILE @@fetch_status = 0 BEGIN FETCH NEXT FROM attributes into @att; SELECT @attValueC = TableDistinctAi FROM TableDistinctAi(@att); --PRINT @attValueC; SET @attValue = CAST(@attValueC AS INT); IF @attValue > @max SET @max = @attValue; END; CLOSE attributes; DEALLOCATE attributes; --PRINT @max; RETURN @max; END; GO