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.
Output:
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
ENDOutput:
0
1
1
2
3
5
8
13
21
34
Comments
Post a Comment