Hi all.I want to create a query that calculates Fibonacci sequences then inserts them to the table.But the problem is: usnig only once at query and not usnig loop.Here is the tableCREATE TABLE Fib( SentID INT PRIMARY KEY, Number BIGINT NOT NULL)INSERT FibSELECT 1,'1' UNION ALLSELECT 2,'1'
Here is my solution:DECLARE @a INTSET @a=0WHILE @a<10BEGIN INSERT Fib SELECT SentID=MAX(SentID)+1, SUM(Number) FROM ( SELECT TOP 2 SentID , Number FROM Fib ORDER BY Number DESC ) DSET @a=@a+1;END
After execution loop:SentID Number----------- ---------1 12 13 24 35 56 87 138 219 3410 5511 8912 144