SQL Server 2022 and the GENERATE-SERIES command .. a T-SQL language enhancement
Hi Guys, Welcome back! I have to admit that I like to find out what is added in each new version of SQL, especially the T-SQL language part. There will be a lot to talk about .. So let's start! Today we see the first improvement of T-SQL language that the new SQL Server 2022 bring us: the GENERATE_SERIES command The GENERATE_SERIES command I bet that when we are asked to generate a series of numbers such as 1,2,3, .. or 2, 4,6 etc etc immediately we think of the CTE (the well-known "common table expression") or the function of ranking ROW_NUMBER. Someone then invents some more original but still functional approach. Let's see some ways currently used to generate a series of values: Using a CTE: WITH Cte AS ( SELECT 1 AS x UNION ALL SELECT x + 1 FROM Cte WHERE x < 5 ) SELECT * FROM Cte -- remember to add the option maxrecursion... Executing this command we will have: Or we could use a ranking function: SELECT ROW_NUMBER () OVER (Ordery...