What’s New in SQL Server 2022: GENERATE_SERIES()

I’ve been doing a lot of work with SQL Server 2022 lately and one of my absolute favorite new features that I just came across today is the GENERATE_SERIES() built-in table function. I just happened to see it in the Books Online content while looking up the syntax for something else.

GENERATE_SERIES (Transact-SQL) – SQL Server | Microsoft Learn

SELECT * FROM GENERATE_SERIES(0,100)

So simple, yet so utilitarian. There are countless scenarios where a sequential table of numbers is useful in code. It can easily solve a lot of situations you would typically use a RBAR (row-by-agonizing-row) loop-based process. What is also great about this function is that it also allows the definition of a step increment easily:

SELECT * FROM GENERATE_SERIES(0,10000,100)

Additionally, the function allows variables to be used for the start, stop and increment values. What a great addition to the TSQL syntax!

Leave a Reply

Your email address will not be published. Required fields are marked *

Other articles

Imagine feeling confident enough to handle whatever your database throws at you.

With training and consulting from SQLskills, you’ll be able to solve big problems, elevate your team’s capacity, and take control of your data career.