{"id":30320,"date":"2024-02-27T05:48:00","date_gmt":"2024-02-27T04:48:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=30320"},"modified":"2024-02-29T19:18:01","modified_gmt":"2024-02-29T18:18:01","slug":"sql-server-pivot-with-multiple-fixed-columns","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/","title":{"rendered":"How to Use SQL Server PIVOT with Multiple Fixed Columns ?"},"content":{"rendered":"\n<p>In a previous technical article, we learned the PIVOT query with one unique fixed column, this time we&#8217;ll use a more complex use case, a SQL Server PIVOT case with multiple fixed columns. Indeed, in this different example, the table to pivot has 2 fixed non numeric columns. So the two columns will not be aggregated or calculated and they are also not pivoted.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-1-create-a-sql-table-with-two-or-more-fixed-columns-to-pivot\">1. Create a SQL table with two or more fixed columns to Pivot<\/h2>\n\n\n\n<p>Here we use the same process as in the previous <a href=\"https:\/\/expert-only.com\/en\/ssis\/how-to-pivot-rows-to-columns-using-ssis\/\"><strong>article on the PIVOT operator.<\/strong><\/a> We simply group the data in a different way. Open <a href=\"https:\/\/expert-only.com\/en\/ssms\/download-ssms-18\/\"><strong>SSMS<\/strong><\/a> and execute this query to cerate the table and insert some sample data. Indeed, we simply added the customer ID and Name as 2 new columns.<\/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=\"\">-- Create the sales table with 2 additional columns\n-- The customer ID and the customer name\nCREATE table [dbo].[SALES_with_Customers] (\n    [MONTH]         NVARCHAR(20),\n    [CUSTOMER_ID]   NVARCHAR(20),\n    [CUSTOMER_NAME] NVARCHAR(20),\n    [AMOUNT]        NUMERIC(5)\n)\nGO\n\n-- Insert first sales amount for each month for Customer-001\nINSERT dbo.SALES_with_Customers VALUES ( N'January',  N'Customer-001', N'ONE', 1000)\nINSERT dbo.SALES_with_Customers VALUES ( N'February', N'Customer-001', N'ONE', 2000)\nINSERT dbo.SALES_with_Customers VALUES ( N'March',    N'Customer-001', N'ONE', 3000)\nINSERT dbo.SALES_with_Customers VALUES ( N'April',    N'Customer-001', N'ONE', 4000)\nINSERT dbo.SALES_with_Customers VALUES ( N'May',      N'Customer-001', N'ONE', 5000)\nINSERT dbo.SALES_with_Customers VALUES ( N'June',     N'Customer-001', N'ONE', 6000)\n-- second step for the first customer\nINSERT dbo.SALES_with_Customers VALUES ( N'January',  N'Customer-001', N'ONE', 1500)\nINSERT dbo.SALES_with_Customers VALUES ( N'February', N'Customer-001', N'ONE', 1500)\nINSERT dbo.SALES_with_Customers VALUES ( N'March',    N'Customer-001', N'ONE', 1500)\nINSERT dbo.SALES_with_Customers VALUES ( N'April',    N'Customer-001', N'ONE', 1500)\nINSERT dbo.SALES_with_Customers VALUES ( N'May',      N'Customer-001', N'ONE', 1500)\nINSERT dbo.SALES_with_Customers VALUES ( N'June',     N'Customer-001', N'ONE', 1500)\n\n-- Insert first sales amounts for each month for the Customer-002\nINSERT dbo.SALES_with_Customers VALUES ( N'January',  N'Customer-002', N'TWO', 1100)\nINSERT dbo.SALES_with_Customers VALUES ( N'February', N'Customer-002', N'TWO', 2200)\nINSERT dbo.SALES_with_Customers VALUES ( N'March',    N'Customer-002', N'TWO', 3300)\nINSERT dbo.SALES_with_Customers VALUES ( N'April',    N'Customer-002', N'TWO', 4400)\nINSERT dbo.SALES_with_Customers VALUES ( N'May',      N'Customer-002', N'TWO', 5500)\nINSERT dbo.SALES_with_Customers VALUES ( N'June',     N'Customer-002', N'TWO', 6600)\n-- Insert second sales amount for each month for Customer-002\nINSERT dbo.SALES_with_Customers VALUES ( N'January',  N'Customer-002', N'TWO', 2000)\nINSERT dbo.SALES_with_Customers VALUES ( N'February', N'Customer-002', N'TWO', 2000)\nINSERT dbo.SALES_with_Customers VALUES ( N'March',    N'Customer-002', N'TWO', 2000)\nINSERT dbo.SALES_with_Customers VALUES ( N'April',    N'Customer-002', N'TWO', 2000)\nINSERT dbo.SALES_with_Customers VALUES ( N'May',      N'Customer-002', N'TWO', 2000)\nINSERT dbo.SALES_with_Customers VALUES ( N'June',     N'Customer-002', N'TWO', 2000)\n\n-- Check inserted data\nSELECT \t*\nFROM \tdbo.[SALES_with_Customers];\n<\/pre>\n\n\n\n<p>Note that the source table contains 12 lines per Customer ID and Customer Name, for the 6 first months of the year.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"680\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/pivot-sql-server-multiple-columns-1-source-table-1.jpg\" alt=\"Use a query in SSMS to create the table with multiple fixed columns to pivot \" class=\"wp-image-17034\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/pivot-sql-server-multiple-columns-1-source-table-1.jpg 640w, https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/pivot-sql-server-multiple-columns-1-source-table-1-282x300.jpg 282w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><figcaption class=\"wp-element-caption\"><em>Use a query in SSMS to create the table with multiple fixed columns to pivot <\/em><\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-use-the-pivot-operator-to-manage-multiple-fixed-fields\">2. Use the PIVOT operator to manage multiple fixed fields<\/h2>\n\n\n\n<p>Once the new table is created, build the pivot query. The exact method is used here. The only difference with <a href=\"https:\/\/expert-only.com\/en\/ssis\/how-to-pivot-rows-to-columns-using-ssis\/\">the <strong>more simple PIVOT example<\/strong><\/a> is that all the named columns are listed in the first select statement.<\/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=\"\">SELECT \t*\nFROM (\n    SELECT\n\t  [MONTH],\n\t  [CUSTOMER_ID],\n\t  [CUSTOMER_NAME],\n\t  [AMOUNT]\n    FROM dbo.SALES_with_Customers\n) AS Source_Table\n\nPIVOT (\n    AVG(AMOUNT)\n    FOR MONTH IN ([January], [February], [March], [April], [May], [June])\n) AS Pivot_Table;\n<\/pre>\n\n\n\n<p>Build the query using the same three steps.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>From the source table, select all the columns to pivot and to display: <strong><em>Month, Customer_Id, Customer_Name and Amount<\/em><\/strong><\/li>\n\n\n\n<li>Configure the pivot column and the aggregation, here it&#8217;s <strong><em>AVG(AMOUNT)<\/em><\/strong><\/li>\n\n\n\n<li>Use the <strong><em>PIVOT operator<\/em><\/strong> to execute the transformation on the selected data.<\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"860\" height=\"460\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/pivot-sql-server-multiple-columns-2-build-query.jpg\" alt=\"SQL Server PIVOT query example explained \" class=\"wp-image-17040\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/pivot-sql-server-multiple-columns-2-build-query.jpg 860w, https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/pivot-sql-server-multiple-columns-2-build-query-300x160.jpg 300w, https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/pivot-sql-server-multiple-columns-2-build-query-768x411.jpg 768w\" sizes=\"auto, (max-width: 860px) 100vw, 860px\" \/><figcaption class=\"wp-element-caption\"><em>SQL Server PIVOT query example explained <\/em><\/figcaption><\/figure><\/div>\n\n\n<p>Finally execute the query and check the calculated average of the sales column, displayed in the <em>Amount<\/em> column.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><em>The first customer&#8217;s data<\/em> is available in one unique line now.<\/li>\n\n\n\n<li>Same for <em>Customer-002<\/em>.<\/li>\n\n\n\n<li>Each month is now displayed in a <em>specific dedicated column<\/em>. <\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"740\" height=\"620\" src=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/pivot-sql-server-multiple-columns-3-execute-query.jpg\" alt=\"Table before and after the PIVOT of the rows into columns with SQL Server\" class=\"wp-image-17058\" srcset=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/pivot-sql-server-multiple-columns-3-execute-query.jpg 740w, https:\/\/expert-only.com\/wp-content\/uploads\/2022\/11\/pivot-sql-server-multiple-columns-3-execute-query-300x251.jpg 300w\" sizes=\"auto, (max-width: 740px) 100vw, 740px\" \/><figcaption class=\"wp-element-caption\"><em>Table before and after the PIVOT of the rows into columns with SQL Server<\/em><\/figcaption><\/figure><\/div>\n\n\n<p>The ultimate goal of aggregation can be very different in the usage, it can be to use data for Reporting using one of the <a href=\"https:\/\/segment.com\/data-hub\/data-aggregation\/tools\/\" target=\"_blank\" rel=\"noreferrer noopener\">tools on the market<\/a>. But it can also be to limit the number of lines stored and have a better management of databases volumetry.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-about-the-t-sql-pivot-operator-with-fixed-data\">About the T-SQL PIVOT operator with fixed data<\/h3>\n\n\n\n<p>In conclusion, this exploration of SQL Server PIVOT with multiple fixed columns significantly enhances our ability to manage and interpret complex datasets. By maintaining certain columns fixed while pivoting others, we unlock new dimensions of data analysis and reporting, showcasing the versatility and power of SQL Server for sophisticated data manipulation tasks.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Tutorials on Pivot and Unpivot data operations using MS technologies<\/h5>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/expert-only.com\/en\/t-sql\/how-to-pivot-rows-to-columns-in-sql-server\/\"><strong>How to Pivot Rows To Columns in SQL Server ?<\/strong><\/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=\"RJoIyfeyDO\"><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=l7Tl0BNGpu#?secret=RJoIyfeyDO\" data-secret=\"RJoIyfeyDO\" 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>In a previous technical article, we learned the PIVOT query with one unique fixed column, this time we&#8217;ll use a more complex use case, a SQL Server PIVOT case with multiple fixed columns. Indeed, in this different example, the <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/\" title=\"How to Use SQL Server PIVOT with Multiple Fixed Columns ?\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":10314,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[454],"tags":[],"class_list":{"0":"post-30320","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 Use SQL Server PIVOT with Multiple Fixed Columns ?<\/title>\n<meta name=\"description\" content=\"Learn an advanced SQL Server PIVOT query for tables with multiple fixed columns to include all the non-aggregated, static fields.\" \/>\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-pivot-with-multiple-fixed-columns\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Use SQL Server PIVOT with Multiple Fixed Columns ?\" \/>\n<meta property=\"og:description\" content=\"Learn an advanced SQL Server PIVOT query for tables with multiple fixed columns to include all the non-aggregated, static fields.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/\" \/>\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-27T04:48:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-29T18:18:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/blackboard-573023_1920x1080.jpg\" \/>\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-pivot-with-multiple-fixed-columns\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/\"},\"author\":{\"name\":\"Expert-Only\",\"@id\":\"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef\"},\"headline\":\"How to Use SQL Server PIVOT with Multiple Fixed Columns ?\",\"datePublished\":\"2024-02-27T04:48:00+00:00\",\"dateModified\":\"2024-02-29T18:18:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/\"},\"wordCount\":485,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/expert-only.com\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/blackboard-573023_1920x1080.jpg\",\"articleSection\":[\"T-SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/\",\"url\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/\",\"name\":\"How to Use SQL Server PIVOT with Multiple Fixed Columns ?\",\"isPartOf\":{\"@id\":\"https:\/\/expert-only.com\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/blackboard-573023_1920x1080.jpg\",\"datePublished\":\"2024-02-27T04:48:00+00:00\",\"dateModified\":\"2024-02-29T18:18:01+00:00\",\"description\":\"Learn an advanced SQL Server PIVOT query for tables with multiple fixed columns to include all the non-aggregated, static fields.\",\"breadcrumb\":{\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#primaryimage\",\"url\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/blackboard-573023_1920x1080.jpg\",\"contentUrl\":\"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/blackboard-573023_1920x1080.jpg\",\"width\":1920,\"height\":1080},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"en\",\"item\":\"https:\/\/expert-only.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Use SQL Server PIVOT with Multiple Fixed Columns ?\"}]},{\"@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 Use SQL Server PIVOT with Multiple Fixed Columns ?","description":"Learn an advanced SQL Server PIVOT query for tables with multiple fixed columns to include all the non-aggregated, static fields.","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-pivot-with-multiple-fixed-columns\/","og_locale":"en_US","og_type":"article","og_title":"How to Use SQL Server PIVOT with Multiple Fixed Columns ?","og_description":"Learn an advanced SQL Server PIVOT query for tables with multiple fixed columns to include all the non-aggregated, static fields.","og_url":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/","og_site_name":"SQL and IT Tutorials","article_publisher":"https:\/\/www.facebook.com\/ExpertOnlyCom\/","article_published_time":"2024-02-27T04:48:00+00:00","article_modified_time":"2024-02-29T18:18:01+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/blackboard-573023_1920x1080.jpg","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-pivot-with-multiple-fixed-columns\/#article","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/"},"author":{"name":"Expert-Only","@id":"https:\/\/expert-only.com\/en\/#\/schema\/person\/406a9576b52944f018739a42046873ef"},"headline":"How to Use SQL Server PIVOT with Multiple Fixed Columns ?","datePublished":"2024-02-27T04:48:00+00:00","dateModified":"2024-02-29T18:18:01+00:00","mainEntityOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/"},"wordCount":485,"commentCount":0,"publisher":{"@id":"https:\/\/expert-only.com\/en\/#organization"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/blackboard-573023_1920x1080.jpg","articleSection":["T-SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/","url":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/","name":"How to Use SQL Server PIVOT with Multiple Fixed Columns ?","isPartOf":{"@id":"https:\/\/expert-only.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#primaryimage"},"image":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#primaryimage"},"thumbnailUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/blackboard-573023_1920x1080.jpg","datePublished":"2024-02-27T04:48:00+00:00","dateModified":"2024-02-29T18:18:01+00:00","description":"Learn an advanced SQL Server PIVOT query for tables with multiple fixed columns to include all the non-aggregated, static fields.","breadcrumb":{"@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#primaryimage","url":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/blackboard-573023_1920x1080.jpg","contentUrl":"https:\/\/expert-only.com\/wp-content\/uploads\/2022\/09\/blackboard-573023_1920x1080.jpg","width":1920,"height":1080},{"@type":"BreadcrumbList","@id":"https:\/\/expert-only.com\/en\/t-sql\/sql-server-pivot-with-multiple-fixed-columns\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"en","item":"https:\/\/expert-only.com\/en\/"},{"@type":"ListItem","position":2,"name":"How to Use SQL Server PIVOT with Multiple Fixed Columns ?"}]},{"@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\/30320","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=30320"}],"version-history":[{"count":9,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/30320\/revisions"}],"predecessor-version":[{"id":30349,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/30320\/revisions\/30349"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/10314"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=30320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=30320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=30320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}