Thursday, February 16, 2012

Simple Programs for Learners 1. Fibonacci Series

/****************************************************

                FIBONACCI SERIES

*****************************************************/


DECLARE @i INT = 1, @o INT = 2
DECLARE @tbl TABLE(Num INT)

INSERT @tbl
SELECT 0
UNION ALL SELECT 1
UNION ALL SELECT 1

WHILE(@o<1000)
BEGIN
    INSERT @tbl
    SELECT @o

    SET @o = @o + @i
    SET @i = @o - @i
END

SELECT * FROM @tbl
GO

No comments:

Post a Comment