Today, November 23, is Fibonacci Day.
Every year on 11/23 we honor Leonardo Bon(anchor)acci, the 13th-century Italian mathematician better known as Fibonacci (a contraction of filius Bonacci – “son of Bonacci”). Although he did not invent the sequence that bears his name, Fibonacci introduced it to the Western world in his 1202 book Liber Abaci, forever influencing mathematics, nature, and computing.
Why November 23?
In the mm/dd date format, today is written as 11/23. The digits 1, 1, 2, 3 are the beginning of the Fibonacci sequence, where each number is the sum of the two preceding ones:
1, 1, 2, 3, 5, 13, 21, 34, 55, 89, 144, 233, 377, …
Generating the Fibonacci Sequence with a Recursive CTE in SQL Server
One of the most elegant ways to generate the sequence in SQL Server is with a recursive Common Table Expression (CTE). Here is a clean, efficient example:
-- Happy Fibonacci Day! (11/23)
WITH Fibonacci AS (
-- Anchor members: the first two numbers
SELECT 1 AS Position,
1 AS FibNumber
UNION ALL
SELECT 2 AS Position,
1 AS FibNumber
UNION ALL
-- Recursive part
SELECT Position + 1,
FibNumber + LAG(FibNumber, 1) OVER (ORDER BY Position) AS FibNumber
FROM Fibonacci
WHERE Position < 50 -- safety limit (or use your own condition)
)
SELECT Position, FibNumber
FROM Fibonacci
OPTION (MAXRECURSION 0); -- remove the default 100-recursion limit
Learn More About Recursive CTEs
Recursive CTEs are among the most powerful features in SQL Server. To master everything from basic recursion to advanced hierarchical queries and performance tuning, download my free e-book:
![]() |
Common Table Expressions – From Basic to Advanced Download the free e-book here: https://stedman.us/ctebook The book includes multiple Fibonacci examples along with dozens of real-world recursive CTE patterns. |
Happy Fibonacci Day!
More from Stedman Solutions:
Steve and the team at Stedman Solutions are here for all your SQL Server needs.
Contact us today for your free 30 minute consultation..
We are ready to help!

