{"id":7598,"date":"2024-02-26T05:28:00","date_gmt":"2024-02-26T04:28:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=7598"},"modified":"2024-02-29T19:12:52","modified_gmt":"2024-02-29T18:12:52","slug":"how-to-pivot-rows-to-columns-in-sql-server","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/","title":{"rendered":"How to Pivot Rows To Columns in SQL Server ? Simple Query"},"content":{"rendered":"\n<h4 class=\"wp-block-heading has-text-align-left\"><em>How to transform data from rows into columns using a SQL Server query?<\/em><\/h4>\n\n\n\n<p>Follow this SQL tutorial and query examples on how to use the SQL Server PIVOT operator to convert rows of data into columns. But the syntax is not straightforward, especially for beginners. Indeed, in order to work, the names of the target columns must be provided. And they must match the content of the pivoted column. This simple Pivot query example shows how to build and adapt your own query step by step. It simply moves the lines containing the months names to columns while computing the average amount of sales for each month.<\/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\/how-to-pivot-rows-to-columns-in-sql-server\/#1-sql-server-pivot-queries-and-aggregations\" >1. SQL Server Pivot queries and aggregations<\/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\/how-to-pivot-rows-to-columns-in-sql-server\/#2-create-a-sql-server-table-to-transform-from-rows-to-columns\" >2. Create a SQL Server table to transform from rows to columns<\/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\/how-to-pivot-rows-to-columns-in-sql-server\/#3-build-and-run-the-sql-server-pivot-query-with-one-fixed-column\" >3. Build and run the SQL Server PIVOT query with one fixed column<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-1-sql-server-pivot-queries-and-aggregations\"><span class=\"ez-toc-section\" id=\"1-sql-server-pivot-queries-and-aggregations\"><\/span>1. SQL Server Pivot queries and aggregations<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In the other hand, if we don&#8217;t want to have any aggregation in the new results lines, then we need exactly one line per column created. In the example below we do a pivot with an aggregation and we use the average function. And only the six first months of the year are used and pivoted, namely January to June. It&#8217;s easy to extend to the end of the year by adding the next 6 months. To do so, just copy\/paste the data creation and query, and add the missing months.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-create-a-sql-server-table-to-transform-from-rows-to-columns\"><span class=\"ez-toc-section\" id=\"2-create-a-sql-server-table-to-transform-from-rows-to-columns\"><\/span>2. Create a SQL Server table to transform from rows to columns<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Before building the query, create the sample table with this T-SQL script, simply copy and paste it to your SSMS window.<\/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=\"\">-- If table exits, drop it\nIF exists( \tSELECT \t1 FROM sys.objects\n            WHERE \tobject_id = object_id(N'[dbo].[SALES]') \n                AND type in (N'U') )\nBEGIN \t\n    DROP TABLE [dbo].[SALES]\nEND\nGO\n\n-- SALES table creation\nCREATE table [dbo].[SALES] (\n    [MONTH] NVARCHAR(20),\n    [AMOUNT] NUMERIC(5)\n)\nGO\n\n-- Insert first sales amount for each month\nINSERT INTO dbo.SALES ( MONTH, AMOUNT ) VALUES ( N'January', 1000)\nINSERT INTO dbo.SALES ( MONTH, AMOUNT ) VALUES ( N'February', 2000)\nINSERT INTO dbo.SALES ( MONTH, AMOUNT ) VALUES ( N'March', 3000)\nINSERT INTO dbo.SALES ( MONTH, AMOUNT ) VALUES ( N'April', 4000)\nINSERT INTO dbo.SALES ( MONTH, AMOUNT ) VALUES ( N'May', 5000)\nINSERT INTO dbo.SALES ( MONTH, AMOUNT ) VALUES ( N'June', 6000)\n\n-- Insert second sales amount for each month\nINSERT INTO dbo.SALES ( MONTH, AMOUNT ) VALUES ( N'January', 1100)\nINSERT INTO dbo.SALES ( MONTH, AMOUNT ) VALUES ( N'February', 2200)\nINSERT INTO dbo.SALES ( MONTH, AMOUNT ) VALUES ( N'March', 3300)\nINSERT INTO dbo.SALES ( MONTH, AMOUNT ) VALUES ( N'April', 4400)\nINSERT INTO dbo.SALES ( MONTH, AMOUNT ) VALUES ( N'May', 5500)\nINSERT INTO dbo.SALES ( MONTH, AMOUNT ) VALUES ( N'June', 6600)\n\n-- Check inserted data\nSELECT \t*\nFROM \tdbo.SALES;\n<\/pre>\n\n\n\n<p>The SQL Server table <a href=\"https:\/\/www.investopedia.com\/terms\/p\/pivot.asp\" target=\"_blank\" rel=\"noreferrer noopener\">to pivot<\/a> is presented here in lines and 2 columns are available. The goal for the next step is to have each month with an average value of the sales.<\/p>\n\n\n<div class=\"wp-block-image wp-image-374 size-full\">\n<figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"628\" height=\"284\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/10\/SQL-Server-Insert-Sales-Data-before-pivot.png\" alt=\"SQL table with data in lines before using the pivot operator\" class=\"wp-image-30321\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2023\/10\/SQL-Server-Insert-Sales-Data-before-pivot.png 628w, https:\/\/expert-only.com\/wp-content\/uploads\/2023\/10\/SQL-Server-Insert-Sales-Data-before-pivot-300x136.png 300w\" sizes=\"auto, (max-width: 628px) 100vw, 628px\" \/><figcaption class=\"wp-element-caption\"><em>SQL table with data in lines before using the pivot operator<\/em><\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-3-build-and-run-the-sql-server-pivot-query-with-one-fixed-column\"><span class=\"ez-toc-section\" id=\"3-build-and-run-the-sql-server-pivot-query-with-one-fixed-column\"><\/span>3. Build and run the SQL Server PIVOT query with one fixed column<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The query to pivot rows into columns is compound of these three parts,&nbsp;it computes the average sales per month:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>A selection of the aggregated column and the months<\/strong>, each column called explicitly.<\/li>\n\n\n\n<li><strong>The sub-query with the original selection<\/strong> of data.<\/li>\n\n\n\n<li><strong>The PIVOT itself using the AVG aggregation<\/strong> function.<\/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=\"\">SELECT \t'Average SALES' AS [SALES_PER_MONTH],\n        [January], [February], [March], [April], [May], [June]\nFROM (\n    SELECT [MONTH], [AMOUNT]\n    FROM dbo.SALES\n) AS SourceTable\nPIVOT (\n    AVG(AMOUNT)\n    FOR MONTH IN ([January], [February], [March], [April], [May],[June])\n) AS PivotTable;\n<\/pre>\n\n\n\n<p>The result of the query appears in columns after the query using PIVOT.<\/p>\n\n\n<div class=\"wp-block-image wp-image-375 size-full\">\n<figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/expert-only.net\/wp-content\/uploads\/2017\/06\/PIVOT-Query-SQL-Server.png\" alt=\"SQL Server PIVOT query to transpose rows into columns\" class=\"wp-image-375\"\/><figcaption class=\"wp-element-caption\"><em>SQL Server PIVOT query to transpose rows into columns<\/em><\/figcaption><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-about-the-simple-pivot-query-use-case\">About the simple Pivot query use case<\/h3>\n\n\n\n<p>To finish, this T-SQL tutorial explains how to use the PIVOT operator in SQL Server with 2 step by step examples. To go further and query system tables metadata, use the <a href=\"https:\/\/expert-only.com\/en\/t-sql\/display-the-modification-date-of-a-sql-server-table\/\">MS SQL query to display the date and time of the last modification of a table<\/a>. Of course you can also do the reverse operation to transpose columns into rows using the <a href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/\">UNPIVOT operator<\/a>.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">More tutorials about how to Pivot and Unpivot data<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/\">SQL Server PIVOT with Multiple Fixed Columns<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/expert-only.com\/en\/excel\/pivot-excel-table\/\">Tutorial to Pivot Excel table columns into rows.<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/expert-only.com\/en\/excel\/create-excel-pivot-table\/\">How to create an Excel pivot table to analyse data?<\/a><\/li>\n<\/ul>\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=\"uctEruuWE5\"><a href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/\">SQL Server UNPIVOT Example<\/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;SQL Server UNPIVOT Example&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-unpivot\/embed\/#?secret=T0s7KDloUn#?secret=uctEruuWE5\" data-secret=\"uctEruuWE5\" 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>How to transform data from rows into columns using a SQL Server query? Follow this SQL tutorial and query examples on how to use the SQL Server PIVOT operator to convert rows of data into columns. But the syntax <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/\" title=\"How to Pivot Rows To Columns in SQL Server ? Simple Query\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":5735,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[],"class_list":{"0":"post-7598","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>How to Pivot Rows To Columns in SQL Server ? Simple Query<\/title>\n<meta name=\"description\" content=\"Example of how to use the SQL Server PIVOT query to transform data from rows to columns with one unique fixed column.\" \/>\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\/how-to-pivot-rows-to-columns-in-sql-server\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Pivot Rows To Columns in SQL Server ? Simple Query\" \/>\n<meta property=\"og:description\" content=\"Example of how to use the SQL Server PIVOT query to transform data from rows to columns with one unique fixed column.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/\" \/>\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-02-26T04:28:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-29T18:12:52+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/board-953155_1920-1024x576.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"576\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\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\/how-to-pivot-rows-to-columns-in-sql-server\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"How to Pivot Rows To Columns in SQL Server ? Simple Query\",\"datePublished\":\"2024-02-26T04:28:00+00:00\",\"dateModified\":\"2024-02-29T18:12:52+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/\"},\"wordCount\":488,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/board-953155_1920.png\",\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/\",\"url\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/\",\"name\":\"How to Pivot Rows To Columns in SQL Server ? Simple Query\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/board-953155_1920.png\",\"datePublished\":\"2024-02-26T04:28:00+00:00\",\"dateModified\":\"2024-02-29T18:12:52+00:00\",\"description\":\"Example of how to use the SQL Server PIVOT query to transform data from rows to columns with one unique fixed column.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/board-953155_1920.png\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/board-953155_1920.png\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Pivot Rows To Columns in SQL Server ? Simple Query\"}]},{\"@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":"How to Pivot Rows To Columns in SQL Server ? Simple Query","description":"Example of how to use the SQL Server PIVOT query to transform data from rows to columns with one unique fixed column.","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\/how-to-pivot-rows-to-columns-in-sql-server\/","og_locale":"en_US","og_type":"article","og_title":"How to Pivot Rows To Columns in SQL Server ? Simple Query","og_description":"Example of how to use the SQL Server PIVOT query to transform data from rows to columns with one unique fixed column.","og_url":"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2024-02-26T04:28:00+00:00","article_modified_time":"2024-02-29T18:12:52+00:00","og_image":[{"width":1024,"height":576,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/board-953155_1920-1024x576.png","type":"image\/png"}],"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\/how-to-pivot-rows-to-columns-in-sql-server\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"How to Pivot Rows To Columns in SQL Server ? Simple Query","datePublished":"2024-02-26T04:28:00+00:00","dateModified":"2024-02-29T18:12:52+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/"},"wordCount":488,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/board-953155_1920.png","articleSection":["T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/","url":"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/","name":"How to Pivot Rows To Columns in SQL Server ? Simple Query","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/board-953155_1920.png","datePublished":"2024-02-26T04:28:00+00:00","dateModified":"2024-02-29T18:12:52+00:00","description":"Example of how to use the SQL Server PIVOT query to transform data from rows to columns with one unique fixed column.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/board-953155_1920.png","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2017\/06\/board-953155_1920.png","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"How to Pivot Rows To Columns in SQL Server ? Simple Query"}]},{"@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\/7598","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=7598"}],"version-history":[{"count":29,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/7598\/revisions"}],"predecessor-version":[{"id":30346,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/7598\/revisions\/30346"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/5735"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=7598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=7598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=7598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}