{"id":19713,"date":"2022-10-05T16:06:52","date_gmt":"2022-10-05T20:06:52","guid":{"rendered":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/?p=19713"},"modified":"2022-10-05T16:12:13","modified_gmt":"2022-10-05T20:12:13","slug":"whats-new-in-sql-server-2022-generate_series","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/","title":{"rendered":"What&#8217;s New in SQL Server 2022: GENERATE_SERIES()"},"content":{"rendered":"\n<p>I&#8217;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.<\/p>\n\n\n\n<p><a href=\"https:\/\/learn.microsoft.com\/en-us\/sql\/t-sql\/functions\/generate-series-transact-sql?view=sql-server-ver16\">GENERATE_SERIES (Transact-SQL) &#8211; SQL Server | Microsoft Learn<\/a><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT * FROM GENERATE_SERIES(0,100)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image-1.png\"><img fetchpriority=\"high\" decoding=\"async\" width=\"384\" height=\"346\" src=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image-1.png\" alt=\"\" class=\"wp-image-19716\" srcset=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image-1.png 384w, https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image-1-300x270.png 300w\" sizes=\"(max-width: 384px) 100vw, 384px\" \/><\/a><\/figure>\n\n\n\n<p>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:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: sql; title: ; notranslate\" title=\"\">\nSELECT * FROM GENERATE_SERIES(0,10000,100)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image.png\"><img decoding=\"async\" width=\"565\" height=\"344\" src=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image.png\" alt=\"\" class=\"wp-image-19714\" srcset=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image.png 565w, https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image-300x183.png 300w\" sizes=\"(max-width: 565px) 100vw, 565px\" \/><\/a><\/figure>\n\n\n\n<p>Additionally, the function allows variables to be used for the start, stop and increment values.  What a great addition to the TSQL syntax!<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;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) &#8211; SQL [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48,64],"tags":[],"class_list":["post-19713","post","type-post","status-publish","format-standard","hentry","category-sql-server","category-sql-server-2022"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>What&#039;s New in SQL Server 2022: GENERATE_SERIES() - Jonathan Kehayias<\/title>\n<meta name=\"description\" content=\"Learn about the new GENERATE_SERIES function in SQL Server 2022 for generating numeric series on the fly.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What&#039;s New in SQL Server 2022: GENERATE_SERIES() - Jonathan Kehayias\" \/>\n<meta property=\"og:description\" content=\"Learn about the new GENERATE_SERIES function in SQL Server 2022 for generating numeric series on the fly.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/\" \/>\n<meta property=\"og:site_name\" content=\"Jonathan Kehayias\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-05T20:06:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-05T20:12:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image-1.png\" \/>\n<meta name=\"author\" content=\"Jonathan Kehayias\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jonathan Kehayias\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/whats-new-in-sql-server-2022-generate_series\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/whats-new-in-sql-server-2022-generate_series\\\/\"},\"author\":{\"name\":\"Jonathan Kehayias\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#\\\/schema\\\/person\\\/01c10d94f3648654ef706d5e6305f69c\"},\"headline\":\"What&#8217;s New in SQL Server 2022: GENERATE_SERIES()\",\"datePublished\":\"2022-10-05T20:06:52+00:00\",\"dateModified\":\"2022-10-05T20:12:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/whats-new-in-sql-server-2022-generate_series\\\/\"},\"wordCount\":146,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/whats-new-in-sql-server-2022-generate_series\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/image-1.png\",\"articleSection\":[\"SQL Server\",\"SQL Server 2022\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/whats-new-in-sql-server-2022-generate_series\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/whats-new-in-sql-server-2022-generate_series\\\/\",\"url\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/whats-new-in-sql-server-2022-generate_series\\\/\",\"name\":\"What's New in SQL Server 2022: GENERATE_SERIES() - Jonathan Kehayias\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/whats-new-in-sql-server-2022-generate_series\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/whats-new-in-sql-server-2022-generate_series\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/image-1.png\",\"datePublished\":\"2022-10-05T20:06:52+00:00\",\"dateModified\":\"2022-10-05T20:12:13+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#\\\/schema\\\/person\\\/01c10d94f3648654ef706d5e6305f69c\"},\"description\":\"Learn about the new GENERATE_SERIES function in SQL Server 2022 for generating numeric series on the fly.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/whats-new-in-sql-server-2022-generate_series\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/whats-new-in-sql-server-2022-generate_series\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/whats-new-in-sql-server-2022-generate_series\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/image-1.png\",\"contentUrl\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/wp-content\\\/uploads\\\/2022\\\/10\\\/image-1.png\",\"width\":384,\"height\":346},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/whats-new-in-sql-server-2022-generate_series\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server\",\"item\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/category\\\/sql-server\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"What&#8217;s New in SQL Server 2022: GENERATE_SERIES()\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#website\",\"url\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/\",\"name\":\"Jonathan Kehayias - The Rambling DBA\",\"description\":\"The Rambling DBA\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.sqlskills.com\\\/blogs\\\/jonathan\\\/#\\\/schema\\\/person\\\/01c10d94f3648654ef706d5e6305f69c\",\"name\":\"Jonathan Kehayias\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g\",\"caption\":\"Jonathan Kehayias\"},\"sameAs\":[\"http:\\\/\\\/3.209.169.194\\\/blogs\\\/jonathan\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What's New in SQL Server 2022: GENERATE_SERIES() - Jonathan Kehayias","description":"Learn about the new GENERATE_SERIES function in SQL Server 2022 for generating numeric series on the fly.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/","og_locale":"en_US","og_type":"article","og_title":"What's New in SQL Server 2022: GENERATE_SERIES() - Jonathan Kehayias","og_description":"Learn about the new GENERATE_SERIES function in SQL Server 2022 for generating numeric series on the fly.","og_url":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/","og_site_name":"Jonathan Kehayias","article_published_time":"2022-10-05T20:06:52+00:00","article_modified_time":"2022-10-05T20:12:13+00:00","og_image":[{"url":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image-1.png","type":"","width":"","height":""}],"author":"Jonathan Kehayias","twitter_misc":{"Written by":"Jonathan Kehayias","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/#article","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/"},"author":{"name":"Jonathan Kehayias","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#\/schema\/person\/01c10d94f3648654ef706d5e6305f69c"},"headline":"What&#8217;s New in SQL Server 2022: GENERATE_SERIES()","datePublished":"2022-10-05T20:06:52+00:00","dateModified":"2022-10-05T20:12:13+00:00","mainEntityOfPage":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/"},"wordCount":146,"commentCount":0,"image":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image-1.png","articleSection":["SQL Server","SQL Server 2022"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/","url":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/","name":"What's New in SQL Server 2022: GENERATE_SERIES() - Jonathan Kehayias","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/#primaryimage"},"image":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/#primaryimage"},"thumbnailUrl":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image-1.png","datePublished":"2022-10-05T20:06:52+00:00","dateModified":"2022-10-05T20:12:13+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#\/schema\/person\/01c10d94f3648654ef706d5e6305f69c"},"description":"Learn about the new GENERATE_SERIES function in SQL Server 2022 for generating numeric series on the fly.","breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/#primaryimage","url":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image-1.png","contentUrl":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-content\/uploads\/2022\/10\/image-1.png","width":384,"height":346},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/whats-new-in-sql-server-2022-generate_series\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/"},{"@type":"ListItem","position":2,"name":"SQL Server","item":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/category\/sql-server\/"},{"@type":"ListItem","position":3,"name":"What&#8217;s New in SQL Server 2022: GENERATE_SERIES()"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/","name":"Jonathan Kehayias - The Rambling DBA","description":"The Rambling DBA","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/#\/schema\/person\/01c10d94f3648654ef706d5e6305f69c","name":"Jonathan Kehayias","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/86630e27f5deecc5c393ea57fc7c3b6a068949f4fd6b5309f81de5a276f12855?s=96&d=mm&r=g","caption":"Jonathan Kehayias"},"sameAs":["http:\/\/3.209.169.194\/blogs\/jonathan"]}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/posts\/19713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/comments?post=19713"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/posts\/19713\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/media?parent=19713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/categories?post=19713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/jonathan\/wp-json\/wp\/v2\/tags?post=19713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}