Posts

Showing posts from June, 2016

Print Fibonacci Series in SQL

Some times you were asked to write a program to print Fibonacci series in interview. So below is the SQL query that will print the Fibonacci series. Copy , Paste and run. DECLARE @A INT = 1 , @B INT = 0 , @C INT = 0 DECLARE @Limit INT = 50 WHILE ( @C <= @LIMIT ) BEGIN        PRINT @C        SET @C = @A + @B        SET @A = @B        SET @B = @C   END Output:  0 1 1 2 3 5 8 13 21 34