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.
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!