{"id":9107,"date":"2024-03-13T07:08:00","date_gmt":"2024-03-13T06:08:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=9107"},"modified":"2024-03-13T11:18:12","modified_gmt":"2024-03-13T10:18:12","slug":"sql-server-unpivot","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/","title":{"rendered":"SQL Server UNPIVOT Example"},"content":{"rendered":"\n<p><strong>Using this T-SQL example, you can easily transform columns into rows with just one step thanks to the SQL Server UNPIVOT function.<\/strong><\/p>\n\n\n\n<p>It is the exact opposite of the PIVOT query. In this example, only the six first months of the year are used as columns, namely January to June. But you can extend the query to all 12 periods of the year by adding the missing ones.\u00a0<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#1-create-data-to-transform-into-rows-using-unpivot-operator\" >1. Create data to transform into rows using UNPIVOT operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#2-insert-data-in-the-source-table-to-transform\" >2. Insert data in the source table to transform<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#3-sql-server-unpivot-query-to-transform-columns-into-rows\" >3. SQL Server UNPIVOT query to transform columns into rows<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-1-create-data-to-transform-into-rows-using-unpivot-operator\"><span class=\"ez-toc-section\" id=\"1-create-data-to-transform-into-rows-using-unpivot-operator\"><\/span>1. Create data to transform into rows using UNPIVOT operator<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For example, the SQL Server Sales table contains one type column and the month&#8217;s columns. They contain respectively the type and the amount of sales for the month. To start, just copy and paste the SQL query for the table creation inside SSMS.<\/p>\n\n\n\n<p><strong>First of all, create the sample table using this script, simply copy and paste the example in your SQL Server Management Studio window.<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- First of all DROP the Sales by month table if it already exists in the db\nIF EXISTS( \n\tSELECT 1 FROM sys.objects\n     WHERE object_id = object_id(N'[dbo].[SALES_BY_MONTH]')\n\t\tAND type in (N'U') )\n-- BEGIN DROP TABLE [dbo].[SALES_BY_MONTH]\nEND;\n\n-- Create the SALES table\nCREATE table [dbo].[SALES_BY_MONTH] (\n    [SalesType] NVARCHAR(20),\n    [January] NUMERIC(5),\n    [February] NUMERIC(5),\n    [March] NUMERIC(5),\n    [April] NUMERIC(5),\n    [May] NUMERIC(5),\n    [June] NUMERIC(5)\n);\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-insert-data-in-the-source-table-to-transform\"><span class=\"ez-toc-section\" id=\"2-insert-data-in-the-source-table-to-transform\"><\/span>2. Insert data in the source table to transform<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>Next, insert the data in the table to be transposed. Each SQL data insertion adds 12 new sales amounts. One column per month, with the associated sales type. <\/strong><\/p>\n\n\n\n<p>Add the missing months if necessary. This way you will be able to transform the 12 months of the year from columns to rows in one single SQL Server query.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- Insert sample sales data for each month: i.e. from January to June\n-- The month columns will be pivoted from columns to lines\nINSERT INTO dbo.SALES_BY_MONTH ( [SalesType], [January], [February], [March], [April], [May], [June] )\nVALUES ( N'Sales', 1000, 2000, 3000, 4000, 5000, 6000);\n\nINSERT INTO dbo.SALES_BY_MONTH ( [SalesType], [January], [February], [March], [April], [May], [June] )\nVALUES ( N'Discounts', 100, 200, 300, 400, 500, 600);\n\nINSERT INTO dbo.SALES_BY_MONTH ( [SalesType], [January], [February], [March], [April], [May], [June] )\nVALUES ( N'Offers', 10, 20, 30, 40, 50, 60);\n\n-- Check the lines inserted in the sales table\nSELECT * \nFROM   dbo.SALES_BY_MONTH;<\/pre>\n\n\n<div class=\"wp-block-image wp-image-394 size-full\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/expert-only.net\/wp-content\/uploads\/2017\/06\/UNPIVOT-Source-Table-SQL-Server.png\" alt=\"Insert data to transform from columns to rows using T-SQL UNPIVOT\" class=\"wp-image-394\"\/><figcaption class=\"wp-element-caption\"><em>Insert data to transform from columns to rows using T-SQL UNPIVOT<\/em><\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-3-sql-server-unpivot-query-to-transform-columns-into-rows\"><span class=\"ez-toc-section\" id=\"3-sql-server-unpivot-query-to-transform-columns-into-rows\"><\/span>3. SQL Server UNPIVOT query to transform columns into rows<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Finally, the SQL Server UNPIVOT function is compound of 3 different steps&nbsp; to transpose the columns in rows.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The selection of the 3 result columns, i.e. Type, Month and Amount.<\/li>\n\n\n\n<li>Then the SQL sub-query with the original selection of data.<\/li>\n\n\n\n<li>The UNPIVOT operation itself with the 6 months named explicitly.<\/li>\n<\/ol>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"mssql\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">-- UNPIVOT Columns to Rows with SQL Query\nSELECT [TYPE], Month, Amount\nFROM (\t\n\tSELECT [TYPE], [January], [February], [March], [April], [May], [June]\n\tFROM dbo.SALES_BY_MONTH \t) sbm\nUNPIVOT\n   (Amount FOR Month IN \n      ([January], [February], [March], [April], [May], [June])\n)AS SalesUnPivot;\n<\/pre>\n\n\n<div class=\"wp-block-image wp-image-395 size-full\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/expert-only.net\/wp-content\/uploads\/2017\/06\/SQL-Server-UNPIVOT-Columns-To-Rows.png\" alt=\"SQL Server UNPIVOT Example query in SSMS\" class=\"wp-image-395\"\/><figcaption class=\"wp-element-caption\"><em>SQL Server UNPIVOT Example query in SSMS<\/em><\/figcaption><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-about-the-pivot-and-unpivot-sql-server-operators\">About the PIVOT and UNPIVOT SQL Server Operators<\/h3>\n\n\n\n<p>In addition, if you are still struggling with this SQL Server UNPIVOT operator and its syntax, just copy paste the example and repeat the three steps by adapting to your real case. Start by renaming the columns to understand how it works. In conclusion, to read mode details, the official Microsoft documentation for the <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/t-sql\/queries\/from-using-pivot-and-unpivot?view=sql-server-2017\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">unpivot function<\/a> is available. The UNPIVOT is the opposite&nbsp;of the <a href=\"https:\/\/dictionary.cambridge.org\/dictionary\/english\/pivot\" target=\"_blank\" rel=\"noreferrer noopener\">PIVOT<\/a> function, here is&nbsp;another short tutorial to use the <a href=\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/\"><strong>SQL Server PIVOT function<\/strong><\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"ktV5oTKt4H\"><a href=\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/\">How to Pivot Rows To Columns in SQL Server ? Simple Query<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;How to Pivot Rows To Columns in SQL Server ? Simple Query&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/embed\/#?secret=K4hWBDYRJg#?secret=ktV5oTKt4H\" data-secret=\"ktV5oTKt4H\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Using this T-SQL example, you can easily transform columns into rows with just one step thanks to the SQL Server UNPIVOT function. It is the exact opposite of the PIVOT query. In this example, only the six first months <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/\" title=\"SQL Server UNPIVOT Example\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":6026,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[],"class_list":{"0":"post-9107","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-t-sql"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.7 (Yoast SEO v26.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL Server UNPIVOT Example - T-SQL<\/title>\n<meta name=\"description\" content=\"Use the SQL Server UNPIVOT operator to transform source data from columns into rows, this T-SQL query example is explained step by step.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server UNPIVOT Example\" \/>\n<meta property=\"og:description\" content=\"Use the SQL Server UNPIVOT operator to transform source data from columns into rows, this T-SQL query example is explained step by step.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/\" \/>\n<meta property=\"og:site_name\" content=\"SQL and IT Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-13T06:08:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-13T10:18:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/motivation_dark_melbourne-city-center-buidings-83992FC8BF0_1920x1080.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Expert-Only\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@expert_only\" \/>\n<meta name=\"twitter:site\" content=\"@expert_only\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Expert-Only\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"SQL Server UNPIVOT Example\",\"datePublished\":\"2024-03-13T06:08:00+00:00\",\"dateModified\":\"2024-03-13T10:18:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/\"},\"wordCount\":382,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/motivation_dark_melbourne-city-center-buidings-83992FC8BF0_1920x1080.jpeg\",\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/\",\"url\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/\",\"name\":\"SQL Server UNPIVOT Example - T-SQL\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/motivation_dark_melbourne-city-center-buidings-83992FC8BF0_1920x1080.jpeg\",\"datePublished\":\"2024-03-13T06:08:00+00:00\",\"dateModified\":\"2024-03-13T10:18:12+00:00\",\"description\":\"Use the SQL Server UNPIVOT operator to transform source data from columns into rows, this T-SQL query example is explained step by step.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/motivation_dark_melbourne-city-center-buidings-83992FC8BF0_1920x1080.jpeg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/motivation_dark_melbourne-city-center-buidings-83992FC8BF0_1920x1080.jpeg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server UNPIVOT Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/expert-only.com\/en\/#website\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"name\":\"SQL and IT Tutorials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/expert-only.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/expert-only.com\/en\/#organization\",\"name\":\"Expert-Only\",\"url\":\"https:\/\/expert-only.com\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg\",\"width\":381,\"height\":174,\"caption\":\"Expert-Only\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/ExpertOnlyCom\/\",\"https:\/\/x.com\/expert_only\",\"https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\",\"name\":\"Expert-Only\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g\",\"caption\":\"Expert-Only\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Server UNPIVOT Example - T-SQL","description":"Use the SQL Server UNPIVOT operator to transform source data from columns into rows, this T-SQL query example is explained step by step.","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:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server UNPIVOT Example","og_description":"Use the SQL Server UNPIVOT operator to transform source data from columns into rows, this T-SQL query example is explained step by step.","og_url":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2024-03-13T06:08:00+00:00","article_modified_time":"2024-03-13T10:18:12+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/motivation_dark_melbourne-city-center-buidings-83992FC8BF0_1920x1080.jpeg","type":"image\/jpeg"}],"author":"Expert-Only","twitter_card":"summary_large_image","twitter_creator":"@expert_only","twitter_site":"@expert_only","twitter_misc":{"Written by":"Expert-Only","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"SQL Server UNPIVOT Example","datePublished":"2024-03-13T06:08:00+00:00","dateModified":"2024-03-13T10:18:12+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/"},"wordCount":382,"commentCount":2,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/motivation_dark_melbourne-city-center-buidings-83992FC8BF0_1920x1080.jpeg","articleSection":["T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/","url":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/","name":"SQL Server UNPIVOT Example - T-SQL","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/motivation_dark_melbourne-city-center-buidings-83992FC8BF0_1920x1080.jpeg","datePublished":"2024-03-13T06:08:00+00:00","dateModified":"2024-03-13T10:18:12+00:00","description":"Use the SQL Server UNPIVOT operator to transform source data from columns into rows, this T-SQL query example is explained step by step.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/motivation_dark_melbourne-city-center-buidings-83992FC8BF0_1920x1080.jpeg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/motivation_dark_melbourne-city-center-buidings-83992FC8BF0_1920x1080.jpeg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"SQL Server UNPIVOT Example"}]},{"@type":"WebSite","@id":"https:\/\/expert-only.com\/en\/#website","url":"https:\/\/expert-only.com\/en\/","name":"SQL and IT Tutorials","description":"","publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/expert-only.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/expert-only.com\/en\/#organization","name":"Expert-Only","url":"https:\/\/expert-only.com\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/09\/cropped-logo_Expert-Only.jpg","width":381,"height":174,"caption":"Expert-Only"},"image":{"@id":"https:\/\/expert-only.com\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ExpertOnlyCom\/","https:\/\/x.com\/expert_only","https:\/\/www.youtube.com\/channel\/UCMS5sR_FwAetB0FmciNvUaA"]},{"@type":"Person","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef","name":"Expert-Only","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/084b15660763ff5b13bb60b2f52f97bb?s=96&d=identicon&r=g","caption":"Expert-Only"}}]}},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/9107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=9107"}],"version-history":[{"count":6,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/9107\/revisions"}],"predecessor-version":[{"id":30652,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/9107\/revisions\/30652"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/6026"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=9107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=9107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=9107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}