{"id":107136,"date":"2022-02-02T11:00:00","date_gmt":"2022-02-02T09:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=107136"},"modified":"2022-01-31T15:39:08","modified_gmt":"2022-01-31T13:39:08","slug":"sql-server-pivot-operator-explained","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/","title":{"rendered":"SQL Server PIVOT Operator Explained"},"content":{"rendered":"<h2 class=\"wp-block-heading\" id=\"h-1-introduction\">1. Introduction<\/h2>\n<p>SQL Server has supported the <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/t-sql\/queries\/from-using-pivot-and-unpivot?view=sql-server-ver15\" target=\"_blank\" rel=\"noreferrer noopener\">PIVOT<\/a> operator since version 2005. It is used to generate a multidimensional report by transferring data from the row level to the column level. <\/p>\n<p><span style=\"text-decoration: underline\"><em>PIVOT Syntax<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:sql\">SELECT &lt;non-pivoted column&gt;,  \n    [first pivoted column] AS &lt;column name&gt;,  \n    [second pivoted column] AS &lt;column name&gt;,  \n    ...  \n    [last pivoted column] AS &lt;column name&gt;  \nFROM  \n    (&lt;SELECT query that produces the data&gt;)   \n    AS &lt;alias for the source query&gt;  \nPIVOT  \n(  \n    &lt;aggregation function&gt;(&lt;column being aggregated&gt;)  \nFOR   \n[&lt;column that contains the values that will become column headers&gt;]   \n    IN ( [first pivoted column], [second pivoted column],  \n    ... [last pivoted column])  \n) AS &lt;alias for the pivot table&gt;  \n&lt;optional ORDER BY clause&gt;<\/pre>\n<p>In this example, I will prepare two tables along with sample data and demonstrate the <strong>Pivot <\/strong>operator:<\/p>\n<ul class=\"wp-block-list\">\n<li>Pivot at <strong>category_id<\/strong> from the <strong>products<\/strong> table.<\/li>\n<li>Pivot at <strong>category_name<\/strong> from the <strong>products<\/strong>&#8216;s join table <strong>categories<\/strong>.<\/li>\n<li>Pivot at <strong>category_name<\/strong> to generate a two-dimensional report.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"h-2-technologies-used\">2. Technologies Used<\/h2>\n<p>The example code in this article was built and run using:<\/p>\n<ul class=\"wp-block-list\">\n<li>SQL Server<\/li>\n<li>SQuirrel Client 3.9.0<\/li>\n<li>SQL<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"h-3-setup-data\">3. Setup Data<\/h2>\n<p>In this step, I will create two database tables:<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>categories <\/strong>&#8211; has two columns: <strong>category_id <\/strong>and <strong>category_name<\/strong>. It has three records.<\/li>\n<li><strong>products <\/strong>&#8211; has four columns: <strong>product_id<\/strong>, <strong>category_id,<\/strong> <strong>product_name<\/strong>, and <strong>release_date<\/strong>. It has eight records.<\/li>\n<\/ul>\n<p><span style=\"text-decoration: underline\"><em>setupdata.sql<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:sql\">create table categories (\ncategory_id  INT,\ncategory_name VARCHAR(40)\n);\n\ncreate table products (\nproduct_id INT,\ncategory_id  INT,\nproduct_name VARCHAR(40),\nrelease_date DATE\n);\n\ninsert into categories ( category_id  , category_name ) values(1, 'Mobile');\ninsert into categories ( category_id  , category_name ) values(2, 'Headphone');\ninsert into categories ( category_id  , category_name ) values(3, 'Tablet');\n\ninsert into products ( product_id , category_id  , product_name, release_date ) values(1027,2, 'Headphone 700', '5\/13\/2019');\ninsert into products ( product_id , category_id  , product_name, release_date ) values(1028,2, 'Headphone 450BT', '2\/4\/2020');\ninsert into products ( product_id , category_id  , product_name, release_date ) values(1029,2, 'HD 1000XM3', '8\/5\/2018');\ninsert into products ( product_id , category_id  , product_name, release_date ) values(1030,2, 'HD SoundES18', '1\/1\/2017');\ninsert into products ( product_id , category_id  , product_name, release_date ) values(1021,1, 'APPLE 700', '9\/20\/2019');\ninsert into products ( product_id , category_id  , product_name, release_date ) values(1022,1, 'Samsung 5', '8\/23\/2019');\ninsert into products ( product_id , category_id  , product_name, release_date ) values(1035,3, 'GalatS6', '10\/13\/2019');\ninsert into products ( product_id , category_id  , product_name, release_date ) values(1036,3, 'MS', '6\/13\/2017');<\/pre>\n<p>Checking products table data with a select statement.<\/p>\n<p><span style=\"text-decoration: underline\"><em>select statement<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:sql\">select * from products;<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Products records<\/em><\/span><\/p>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td>product_id<\/td>\n<td>category_id<\/td>\n<td>product_name<\/td>\n<td>release_date<\/td>\n<\/tr>\n<tr>\n<td>1027<\/td>\n<td>2<\/td>\n<td>Headphone 700<\/td>\n<td>5\/13\/2019<\/td>\n<\/tr>\n<tr>\n<td>1028<\/td>\n<td>2<\/td>\n<td>Headphone 450BT<\/td>\n<td>2\/4\/2020<\/td>\n<\/tr>\n<tr>\n<td>1029<\/td>\n<td>2<\/td>\n<td>HD 1000XM3<\/td>\n<td>8\/5\/2018<\/td>\n<\/tr>\n<tr>\n<td>1030<\/td>\n<td>2<\/td>\n<td>HD SoundES18<\/td>\n<td>1\/1\/2017<\/td>\n<\/tr>\n<tr>\n<td>1021<\/td>\n<td>1<\/td>\n<td>APPLE 700<\/td>\n<td>9\/20\/2019<\/td>\n<\/tr>\n<tr>\n<td>1022<\/td>\n<td>1<\/td>\n<td>Samsung 5<\/td>\n<td>8\/23\/2019<\/td>\n<\/tr>\n<tr>\n<td>1035<\/td>\n<td>3<\/td>\n<td>GalatS6<\/td>\n<td>10\/13\/2019<\/td>\n<\/tr>\n<tr>\n<td>1036<\/td>\n<td>3<\/td>\n<td>MS<\/td>\n<td>6\/13\/2017<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>Table 1 Products Records<\/figcaption><\/figure>\n<h3 class=\"wp-block-heading\" id=\"h-3-1-group-by-category-id\"><a name=\"heading31\"><\/a>3.1 Group By Category_id<\/h3>\n<p>In this step, I will query the total product counts based on the <strong>category_id<\/strong>.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p><span style=\"text-decoration: underline\"><em>group by category_id<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:sql\">select category_id, count(*) totalProductCount from products group by category_id;<\/pre>\n<p><strong>Note<\/strong>: the group by column: <strong>category_id<\/strong> is the PIVOT column that will be used at <a href=\"#heading41\">step 4.1<\/a><\/p>\n<p><span style=\"text-decoration: underline\"><em>group by category_id output<\/em><\/span>\n<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td>category_id<\/td>\n<td>totalProductCount<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>4<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>2<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>Table 2 Total Product Count Group by Category_id<\/figcaption><\/figure>\n<p>There are two products with <strong>category_id<\/strong> of 1, four products with <strong>category_id<\/strong> of 2, and 2 products with <strong>category_id<\/strong> of 3.<\/p>\n<p>In <a href=\"http:\/\/squirrel-sql.sourceforge.net\/\" target=\"_blank\" rel=\"noreferrer noopener\">SQuirrel<\/a> client tool, clicking the fifth tab &#8211; <strong>Rotated Table<\/strong>, then it rotates the three rows under the <strong>category_id<\/strong> column into three columns.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Rotated Table Result<\/em>s<\/span> <\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/01\/rotate_table.jpg\"><img decoding=\"async\" width=\"653\" height=\"166\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/01\/rotate_table.jpg\" alt=\"sql pivot - category id\" class=\"wp-image-107165\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/01\/rotate_table.jpg 653w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/01\/rotate_table-300x76.jpg 300w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><\/a><figcaption>Figure 1 Rotated Table &#8211; Category_id<\/figcaption><\/figure>\n<\/div>\n<p>The three columns: <strong>Row_1<\/strong>, <strong>Row_2<\/strong>, and <strong>Row_3<\/strong> are converted from the <strong>category_id<\/strong> row values. In <a href=\"#heading42\">step 4.2<\/a>, I will show how to use the <strong>PIVOT<\/strong> operator to achieve the same rotated results.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-3-2-group-by-with-where-condition\"><a name=\"heading32\"><\/a>3.2 Group By with Where Condition<\/h3>\n<p>In this step, I limit the query results from <a href=\"#heading31\">step 3.1<\/a> by adding a where clause when querying the product counts based on <strong>category_id<\/strong>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Group with Where Clause<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:sql\">select category_id, count(*) productCountsByCat_2019 from products where release_date between '2019-01-01' and '2019-12-31' group by category_id;<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Group By with Where Clause output<\/em><\/span>\n<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td>category_id<\/td>\n<td>productCountsByCat_2019<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>2<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>1<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>Table 3 Product Counts By Category_id in 2019<\/figcaption><\/figure>\n<p>The product counts based on the <strong>category_id<\/strong> are limited to the products released in 2019.<\/p>\n<p>Using the SQuirrel Client tool, click the fifth tab &#8211; <strong>Rotated Table<\/strong>. It rotated the three rows under the <strong>category_id<\/strong> column into three columns.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Rotated table with where clause<\/em><\/span>\n<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/01\/year_rotate_table.jpg\"><img decoding=\"async\" width=\"613\" height=\"276\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/01\/year_rotate_table.jpg\" alt=\"sql pivot - by year\" class=\"wp-image-107166\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/01\/year_rotate_table.jpg 613w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/01\/year_rotate_table-300x135.jpg 300w\" sizes=\"(max-width: 613px) 100vw, 613px\" \/><\/a><figcaption>Figure 2 Rotated Table By Year<\/figcaption><\/figure>\n<\/div>\n<p>The rotated columns are from the <strong>category_id<\/strong> values. The row <strong>productCountsByCat_2019 <\/strong>shows the products released in the year 2019. In <a href=\"#heading43\">step 4.3<\/a>, I will show you how to use the <strong>PIVOT<\/strong> operator to achieve the same rotated results by generating a multidimensional report for all release years.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-4-sql-server-pivot-operator-examples\">4. SQL Server PIVOT Operator Examples<\/h2>\n<p>In this step, I will show three examples that pivot at either <strong>category_id<\/strong> or <strong>category_name<\/strong>.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-4-1-pivot-on-category-id\"><a name=\"heading41\"><\/a>4.1 PIVOT on Category_id<\/h3>\n<p>In this step, I will use the <strong>PIVOT<\/strong> operator to show the product count for each <strong>category_id<\/strong>.  It should have the same results as <a href=\"#heading31\">step 3.1<\/a> after clicking the <strong>Rotated Table<\/strong> tab. The <strong>pivot_column<\/strong> is the <strong>category_id<\/strong> column from the <strong>products<\/strong> table. The aggregation function is the <strong>count<\/strong>(<strong>product_id<\/strong>) function.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Pivot by Category_id<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:sql,highlight:[6,7,8]\">SELECT *\nFROM   (SELECT category_id,\n               product_id\n        FROM   products p) temp_table\n       PIVOT ( Count (product_id)\n             FOR category_id IN ( [1],\n                                  [2],\n                                  [3]) ) pivot_table; <\/pre>\n<p><span style=\"text-decoration: underline\"><em>Query Results<\/em><\/span>\n<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>2<\/td>\n<td>3<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>4<\/td>\n<td>2<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>Table 4 PIVOT by category_id<\/figcaption><\/figure>\n<p>The column names are converted from the 3-row values from <a href=\"https:\/\/examples.javacodegeeks.com\/wp-admin\/post.php?post=107136&amp;action=edit#heading31\">step 3.1<\/a> which are outlined in the query at lines 6, 7, and 8. <\/p>\n<h3 class=\"wp-block-heading\" id=\"h-4-2-pivot-on-category-name\"><a name=\"heading42\"><\/a>4.2 PIVOT on Category_name<\/h3>\n<p>In this step, I will alter the query in <a href=\"#heading41\">step 4.1<\/a> to show the <strong>category_name<\/strong> instead of <strong>category_id<\/strong> for better readability.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Pivot by Category_name<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:sql, highlight:[8,9,10]\">SELECT *\nFROM   (SELECT category_name,\n               product_id\n        FROM   products p\n               INNER JOIN categories c\n                       ON c.category_id = p.category_id) temp_table\n       PIVOT ( Count (product_id)\n             FOR category_name IN ( mobile,\n                                    headphone,\n                                    tablet) ) pivot_table; <\/pre>\n<p><span style=\"text-decoration: underline\"><em>Query Results<\/em><\/span>\n<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td>mobile<\/td>\n<td>headphone<\/td>\n<td>tablet<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>4<\/td>\n<td>2<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>Table 5 Pivot by category_name<\/figcaption><\/figure>\n<p>Here, it has similar data as table 4 but more descriptive column names at lines 8, 9, and 10.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-4-3-pivot-on-category-name-with-release-date\"><a name=\"heading43\"><\/a>4.3 PIVOT on Category_name with Release_date<\/h3>\n<p>In this step, I will generate a two-dimension product count report. It&#8217;s based on <strong>release_year<\/strong> and <strong>category_name<\/strong>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Pivot on Category_name with Release Year<\/em><\/span>\n<\/p>\n<pre class=\"wp-block-preformatted brush:sql\">SELECT *\nFROM   (SELECT category_name,\n               product_id,\n               Year(release_date) release_year\n        FROM   products p\n               INNER JOIN categories c\n                       ON c.category_id = p.category_id) temp_table\n       PIVOT ( Count (product_id)\n             FOR category_name IN ( mobile,\n                                    headphone,\n                                    tablet) ) pivot_table; <\/pre>\n<p><span style=\"text-decoration: underline\"><em>Two-dimensional Report<\/em><\/span>\n<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<td>release_year<\/td>\n<td>mobile<\/td>\n<td>headphone<\/td>\n<td>tablet<\/td>\n<\/tr>\n<tr>\n<td>2017<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>2018<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>2019<\/td>\n<td>2<\/td>\n<td>1<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>2020<\/td>\n<td>0<\/td>\n<td>1<\/td>\n<td>0<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>Table 6 Product count reports by category_name and release year<\/figcaption><\/figure>\n<p>As you can see, the 2-dimensional product count report is based on the <strong>category_name<\/strong> and <strong>release_year<\/strong>. It is generated with a <strong>PIVOT <\/strong>operator and shows the total product count by <strong>category_name<\/strong> for each release year.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-5-summary\">5. Summary<\/h2>\n<p>In this example, I explained the <strong>PIVOT <\/strong>operator with sample data. The <strong>Pivot <\/strong>operator is similar to the <strong>Group By<\/strong> clause but has better readability for reporting. <\/p>\n<h2 class=\"wp-block-heading\" id=\"h-6-download-the-source-code\">6. Download the Source Code<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/01\/sql-pivot.zip\"><strong>SQL Server PIVOT Operator Explained<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction SQL Server has supported the PIVOT operator since version 2005. It is used to generate a multidimensional report by transferring data from the row level to the column level. PIVOT Syntax SELECT &lt;non-pivoted column&gt;, [first pivoted column] AS &lt;column name&gt;, [second pivoted column] AS &lt;column name&gt;, &#8230; [last pivoted column] AS &lt;column name&gt; &hellip;<\/p>\n","protected":false},"author":140,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[46668],"class_list":["post-107136","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sql","tag-sql-server"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL Server PIVOT Operator - Examples Java Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"SQL Server Pivot operator is used to generate a multidimensional report by transferring data from the row level to the column level.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server PIVOT Operator - Examples Java Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"SQL Server Pivot operator is used to generate a multidimensional report by transferring data from the row level to the column level.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-02T09:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Mary Zheng\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Mary Zheng\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/\"},\"author\":{\"name\":\"Mary Zheng\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8a2034fbabcb20a9396e9819261855ae\"},\"headline\":\"SQL Server PIVOT Operator Explained\",\"datePublished\":\"2022-02-02T09:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/\"},\"wordCount\":768,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"SQL Server\"],\"articleSection\":[\"sql\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/\",\"name\":\"SQL Server PIVOT Operator - Examples Java Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2022-02-02T09:00:00+00:00\",\"description\":\"SQL Server Pivot operator is used to generate a multidimensional report by transferring data from the row level to the column level.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Core Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"sql\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"SQL Server PIVOT Operator Explained\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8a2034fbabcb20a9396e9819261855ae\",\"name\":\"Mary Zheng\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Mary-Zheng_avatar_1510732235-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Mary-Zheng_avatar_1510732235-96x96.jpg\",\"caption\":\"Mary Zheng\"},\"description\":\"Mary has graduated from Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She works as a senior Software Engineer in the telecommunications sector where she acts as a leader and works with others to design, implement, and monitor the software solution.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/mary-zheng\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Server PIVOT Operator - Examples Java Code Geeks - 2026","description":"SQL Server Pivot operator is used to generate a multidimensional report by transferring data from the row level to the column level.","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:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server PIVOT Operator - Examples Java Code Geeks - 2026","og_description":"SQL Server Pivot operator is used to generate a multidimensional report by transferring data from the row level to the column level.","og_url":"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2022-02-02T09:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Mary Zheng","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Mary Zheng","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/"},"author":{"name":"Mary Zheng","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8a2034fbabcb20a9396e9819261855ae"},"headline":"SQL Server PIVOT Operator Explained","datePublished":"2022-02-02T09:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/"},"wordCount":768,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["SQL Server"],"articleSection":["sql"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/","url":"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/","name":"SQL Server PIVOT Operator - Examples Java Code Geeks - 2026","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2022-02-02T09:00:00+00:00","description":"SQL Server Pivot operator is used to generate a multidimensional report by transferring data from the row level to the column level.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/sql-server-pivot-operator-explained\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Core Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/"},{"@type":"ListItem","position":4,"name":"sql","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/core-java\/sql\/"},{"@type":"ListItem","position":5,"name":"SQL Server PIVOT Operator Explained"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/8a2034fbabcb20a9396e9819261855ae","name":"Mary Zheng","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Mary-Zheng_avatar_1510732235-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/11\/Mary-Zheng_avatar_1510732235-96x96.jpg","caption":"Mary Zheng"},"description":"Mary has graduated from Mechanical Engineering department at ShangHai JiaoTong University. She also holds a Master degree in Computer Science from Webster University. During her studies she has been involved with a large number of projects ranging from programming and software engineering. She works as a senior Software Engineer in the telecommunications sector where she acts as a leader and works with others to design, implement, and monitor the software solution.","url":"https:\/\/examples.javacodegeeks.com\/author\/mary-zheng\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/107136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/140"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=107136"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/107136\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=107136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=107136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=107136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}