Skip to main content

Posts

Showing posts with the label Recursive Scalar Function in T-SQL

Recursive Scalar Function in T-SQL

CREATE FUNCTION dbo.Fibonacci (@Num integer, @prev integer, @next integer) RETURNS VARCHAR(4000) AS BEGIN DECLARE @returnValue as VARCHAR (4000) = cast(@prev as varchar(4000)); IF (@Num > 0) BEGIN IF (LEN(@returnValue) > 0) BEGIN SET @returnValue = @returnValue + ','; END SET @returnValue = @returnValue + dbo.Fibonacci(@Num - 1, @next, @next + @prev) ; END RETURN @returnValue; END GO ---------------get list select dbo.Fibonacci(10,0,1)