<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; PIVOT Table Example</title>
	<atom:link href="http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Thu, 09 Feb 2012 08:55:56 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: vinay</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-246737</link>
		<dc:creator><![CDATA[vinay]]></dc:creator>
		<pubDate>Wed, 01 Feb 2012 19:28:46 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-246737</guid>
		<description><![CDATA[Hi

I have used Pivot in my Stored procedure.

Like while I was executing, there was a bit server blockings . Is it really due to that. And as per performance point of which is better While Looping is that better or PIVOT is that better.]]></description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>I have used Pivot in my Stored procedure.</p>
<p>Like while I was executing, there was a bit server blockings . Is it really due to that. And as per performance point of which is better While Looping is that better or PIVOT is that better.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bhagat</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-241447</link>
		<dc:creator><![CDATA[bhagat]]></dc:creator>
		<pubDate>Fri, 20 Jan 2012 20:37:23 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-241447</guid>
		<description><![CDATA[hi pinal,


I have doubt can you please help me..

Required  output in this format.

empid  GS NS MS AS  total
1001    3    2     1    2    8
1002    1     4    3     0    8


Below is the  table structure
empid  Shift  Date
1001    GS    01-Jan-2012
1001     GS   02-Jan-2012
1001     GS   03-Jan-2012
1001     NS    04-Jan-2012
1001     NS     05-Jan-2012
1001     MS    06-Jan-2012
1001     AS     07-Jan-2012
1001    AS      07-Jan-2012
1002     GS     01-Jan-2012
1002     NS    02-Jan-2012
.....
.....
....
1002      AS     07-Jan-2012
etc...

Please help me to solve this issue... It&#039;s really urgent
  if you can reply early I&#039;ll really appreciate]]></description>
		<content:encoded><![CDATA[<p>hi pinal,</p>
<p>I have doubt can you please help me..</p>
<p>Required  output in this format.</p>
<p>empid  GS NS MS AS  total<br />
1001    3    2     1    2    8<br />
1002    1     4    3     0    8</p>
<p>Below is the  table structure<br />
empid  Shift  Date<br />
1001    GS    01-Jan-2012<br />
1001     GS   02-Jan-2012<br />
1001     GS   03-Jan-2012<br />
1001     NS    04-Jan-2012<br />
1001     NS     05-Jan-2012<br />
1001     MS    06-Jan-2012<br />
1001     AS     07-Jan-2012<br />
1001    AS      07-Jan-2012<br />
1002     GS     01-Jan-2012<br />
1002     NS    02-Jan-2012<br />
&#8230;..<br />
&#8230;..<br />
&#8230;.<br />
1002      AS     07-Jan-2012<br />
etc&#8230;</p>
<p>Please help me to solve this issue&#8230; It&#8217;s really urgent<br />
  if you can reply early I&#8217;ll really appreciate</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Prithvi Nath Pandey</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-223717</link>
		<dc:creator><![CDATA[Prithvi Nath Pandey]]></dc:creator>
		<pubDate>Thu, 22 Dec 2011 14:24:59 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-223717</guid>
		<description><![CDATA[great , that done my job easy]]></description>
		<content:encoded><![CDATA[<p>great , that done my job easy</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dhanashree</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-167981</link>
		<dc:creator><![CDATA[Dhanashree]]></dc:creator>
		<pubDate>Wed, 14 Sep 2011 10:04:59 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-167981</guid>
		<description><![CDATA[what is the query of converting column fields into row fields by using pivot table?]]></description>
		<content:encoded><![CDATA[<p>what is the query of converting column fields into row fields by using pivot table?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-134581</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Mon, 16 May 2011 10:22:29 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-134581</guid>
		<description><![CDATA[Refer this dynamic PIVOT posting
http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx]]></description>
		<content:encoded><![CDATA[<p>Refer this dynamic PIVOT posting<br />
<a href="http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx" rel="nofollow">http://beyondrelational.com/blogs/madhivanan/archive/2008/08/27/dynamic-pivot-in-sql-server-2005.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Calvin</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-134199</link>
		<dc:creator><![CDATA[Calvin]]></dc:creator>
		<pubDate>Fri, 13 May 2011 04:27:24 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-134199</guid>
		<description><![CDATA[You uses [CA], [AZ], [TX] because you know what is the column,

what if the column is dynamic? Users can add new items at any time.]]></description>
		<content:encoded><![CDATA[<p>You uses [CA], [AZ], [TX] because you know what is the column,</p>
<p>what if the column is dynamic? Users can add new items at any time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Akhtar jahan</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-134178</link>
		<dc:creator><![CDATA[Akhtar jahan]]></dc:creator>
		<pubDate>Fri, 13 May 2011 00:48:10 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-134178</guid>
		<description><![CDATA[Hi Jasmeet,
USE AdventureWorks
GO
SELECT [CA], [AZ], [TX]
FROM
(
SELECT sp.StateProvinceCode
FROM Person.Address a
INNER JOIN Person.StateProvince sp
ON a.StateProvinceID = sp.StateProvinceID
) p
PIVOT
(
COUNT (StateProvinceCode)
FOR StateProvinceCode
IN ([CA], [AZ], [TX])
) AS pvt;


FOR means WHERE. IN  this case 

select COUNT(StateProvinceCode)
FROM P
WHERE StateProvinceCode
IN ([CA], [AZ], [TX])]]></description>
		<content:encoded><![CDATA[<p>Hi Jasmeet,<br />
USE AdventureWorks<br />
GO<br />
SELECT [CA], [AZ], [TX]<br />
FROM<br />
(<br />
SELECT sp.StateProvinceCode<br />
FROM Person.Address a<br />
INNER JOIN Person.StateProvince sp<br />
ON a.StateProvinceID = sp.StateProvinceID<br />
) p<br />
PIVOT<br />
(<br />
COUNT (StateProvinceCode)<br />
FOR StateProvinceCode<br />
IN ([CA], [AZ], [TX])<br />
) AS pvt;</p>
<p>FOR means WHERE. IN  this case </p>
<p>select COUNT(StateProvinceCode)<br />
FROM P<br />
WHERE StateProvinceCode<br />
IN ([CA], [AZ], [TX])</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jasmeet Kaur</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-128505</link>
		<dc:creator><![CDATA[Jasmeet Kaur]]></dc:creator>
		<pubDate>Tue, 12 Apr 2011 16:11:39 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-128505</guid>
		<description><![CDATA[what is mean of FOR keyword in Pivot tables?]]></description>
		<content:encoded><![CDATA[<p>what is mean of FOR keyword in Pivot tables?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: debojyoti</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-121672</link>
		<dc:creator><![CDATA[debojyoti]]></dc:creator>
		<pubDate>Thu, 03 Mar 2011 09:27:31 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-121672</guid>
		<description><![CDATA[Hi All,

The  pivot will not work when the columns are varchar fields .

data

tick rate
FIT	 AAA
FIT	 AA+
SN	 AAA
SN	 AA+
SN	 D
MO	 Ca
MO	 C

I wanna see 
FIT   SN    MO
AAA AAA  Ca
AA+ AA+  C]]></description>
		<content:encoded><![CDATA[<p>Hi All,</p>
<p>The  pivot will not work when the columns are varchar fields .</p>
<p>data</p>
<p>tick rate<br />
FIT	 AAA<br />
FIT	 AA+<br />
SN	 AAA<br />
SN	 AA+<br />
SN	 D<br />
MO	 Ca<br />
MO	 C</p>
<p>I wanna see<br />
FIT   SN    MO<br />
AAA AAA  Ca<br />
AA+ AA+  C</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Praveen Poosapati</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-101526</link>
		<dc:creator><![CDATA[Praveen Poosapati]]></dc:creator>
		<pubDate>Mon, 22 Nov 2010 17:35:12 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-101526</guid>
		<description><![CDATA[Hi, 

I have a table like this..


Product	 element	   value

1	          FOB	   16
1	          Freight	   0.25
1	          Burden	   16.25
2                FOB	   16
2	          Freight	   0.25
2	          Burden	   16.25
2                FOB           18
2                Freight       1.75

Now I am writing a query for the pivot table as ..

SELECT * 
FROM 
(SELECT PRODUCT, ELEMENT, VALUE
 FROM	source_table (NOLOCK) 
) as Data
 PIVOT
 ( AVG(VALUE) FOR ELEMENT IN (WHOLESALE, [FOB], [FREIGHT], [BURDEN])
 )Pivot_Table


I am getting this as a result.


PRODUCT 	FOB	  FREIGHT	    BURDEN
1	                16	   NULL	     NULL
2	                17	   NULL	     NULL


I am getting nulls for the Freight and Burden because (I Think)  they have decimal values. 

Can some one help me out in this and tell me how I can get the desired values for these decimal types also?


Thanks.
-Praveen.]]></description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>I have a table like this..</p>
<p>Product	 element	   value</p>
<p>1	          FOB	   16<br />
1	          Freight	   0.25<br />
1	          Burden	   16.25<br />
2                FOB	   16<br />
2	          Freight	   0.25<br />
2	          Burden	   16.25<br />
2                FOB           18<br />
2                Freight       1.75</p>
<p>Now I am writing a query for the pivot table as ..</p>
<p>SELECT *<br />
FROM<br />
(SELECT PRODUCT, ELEMENT, VALUE<br />
 FROM	source_table (NOLOCK)<br />
) as Data<br />
 PIVOT<br />
 ( AVG(VALUE) FOR ELEMENT IN (WHOLESALE, [FOB], [FREIGHT], [BURDEN])<br />
 )Pivot_Table</p>
<p>I am getting this as a result.</p>
<p>PRODUCT 	FOB	  FREIGHT	    BURDEN<br />
1	                16	   NULL	     NULL<br />
2	                17	   NULL	     NULL</p>
<p>I am getting nulls for the Freight and Burden because (I Think)  they have decimal values. </p>
<p>Can some one help me out in this and tell me how I can get the desired values for these decimal types also?</p>
<p>Thanks.<br />
-Praveen.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Praveen Poosapati</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-101524</link>
		<dc:creator><![CDATA[Praveen Poosapati]]></dc:creator>
		<pubDate>Mon, 22 Nov 2010 17:24:47 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-101524</guid>
		<description><![CDATA[Hi, 

I have a table like this..


Product	element	value
1	FOB	16
1	Freight	0.25
1	Burden	16.25
2	FOB	16
2	Freight	0.25
3	Burden	16.25]]></description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>I have a table like this..</p>
<p>Product	element	value<br />
1	FOB	16<br />
1	Freight	0.25<br />
1	Burden	16.25<br />
2	FOB	16<br />
2	Freight	0.25<br />
3	Burden	16.25</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: terance</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-74412</link>
		<dc:creator><![CDATA[terance]]></dc:creator>
		<pubDate>Wed, 02 Jun 2010 15:34:20 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-74412</guid>
		<description><![CDATA[Hi 
  i want to create a crystal report using Cross tab, do you have any idea  to how to create in sql 2005]]></description>
		<content:encoded><![CDATA[<p>Hi<br />
  i want to create a crystal report using Cross tab, do you have any idea  to how to create in sql 2005</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: fina_el</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-73338</link>
		<dc:creator><![CDATA[fina_el]]></dc:creator>
		<pubDate>Thu, 27 May 2010 02:33:49 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-73338</guid>
		<description><![CDATA[Hi Mr Pinalkumar Dave,
This article are very good. 
However I have some questions which may or may not have to use this.
Please support with your experience which is suitable for me.

I have a table&quot; ProdSchedule
Model  Date upload   Lot_qty   Prod_Date
AAA    2010-05-14    1500      2010-05-15
AAA    2010-05-14    2500      2010-06-18
AAA    2010-05-21    3500      2010-06-01
AAA    2010-05-21    4500      2010-05-25
BBB    2010-05-14    5500      2010-05-05
BBB    2010-05-21    6500      2010-06-04

In this case, i need to compare the lot_qty on period month(get from prod_date)
at every week (this week and last week).

And I need the output like this format:

Model  Date upload   May   June
AAA    2010-05-21    4500  3500
AAA    2010-05-14    1500  2500
DiffA                         3500  1000
BBB    2010-05-21    5500        0
BBB    2010-05-14          0  6500
DiffB                        -5500  6500

Thank You.......]]></description>
		<content:encoded><![CDATA[<p>Hi Mr Pinalkumar Dave,<br />
This article are very good.<br />
However I have some questions which may or may not have to use this.<br />
Please support with your experience which is suitable for me.</p>
<p>I have a table&#8221; ProdSchedule<br />
Model  Date upload   Lot_qty   Prod_Date<br />
AAA    2010-05-14    1500      2010-05-15<br />
AAA    2010-05-14    2500      2010-06-18<br />
AAA    2010-05-21    3500      2010-06-01<br />
AAA    2010-05-21    4500      2010-05-25<br />
BBB    2010-05-14    5500      2010-05-05<br />
BBB    2010-05-21    6500      2010-06-04</p>
<p>In this case, i need to compare the lot_qty on period month(get from prod_date)<br />
at every week (this week and last week).</p>
<p>And I need the output like this format:</p>
<p>Model  Date upload   May   June<br />
AAA    2010-05-21    4500  3500<br />
AAA    2010-05-14    1500  2500<br />
DiffA                         3500  1000<br />
BBB    2010-05-21    5500        0<br />
BBB    2010-05-14          0  6500<br />
DiffB                        -5500  6500</p>
<p>Thank You&#8230;&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Arnon</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-70741</link>
		<dc:creator><![CDATA[Arnon]]></dc:creator>
		<pubDate>Thu, 13 May 2010 18:10:04 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-70741</guid>
		<description><![CDATA[Thanks for the article. I have a question:
Using the example in the article, I want to summarize the data for all states, not just the three, without explicitly listing them. something like:

....FOR StateProvinceCode
IN (StateProvinceCode FROM Person.Address)....

This does not work, I get an error message saying &quot;expecting ID, QUOTED_ID or &#039;.&#039;

Any ideas?]]></description>
		<content:encoded><![CDATA[<p>Thanks for the article. I have a question:<br />
Using the example in the article, I want to summarize the data for all states, not just the three, without explicitly listing them. something like:</p>
<p>&#8230;.FOR StateProvinceCode<br />
IN (StateProvinceCode FROM Person.Address)&#8230;.</p>
<p>This does not work, I get an error message saying &#8220;expecting ID, QUOTED_ID or &#8216;.&#8217;</p>
<p>Any ideas?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fazal Vahora</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-64685</link>
		<dc:creator><![CDATA[Fazal Vahora]]></dc:creator>
		<pubDate>Wed, 07 Apr 2010 08:05:44 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-64685</guid>
		<description><![CDATA[Hi,Pinal Sir

is it  Possible to use morethan one aggregate function in Pivot table?

Like

Select Count(no),sum(value1+value2) ,sum(value3+value4)

Please Give me solution


Thnaks in Advance]]></description>
		<content:encoded><![CDATA[<p>Hi,Pinal Sir</p>
<p>is it  Possible to use morethan one aggregate function in Pivot table?</p>
<p>Like</p>
<p>Select Count(no),sum(value1+value2) ,sum(value3+value4)</p>
<p>Please Give me solution</p>
<p>Thnaks in Advance</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chiranjiv Khemka</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-63607</link>
		<dc:creator><![CDATA[Chiranjiv Khemka]]></dc:creator>
		<pubDate>Wed, 24 Mar 2010 06:05:11 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-63607</guid>
		<description><![CDATA[Hi All,

I too need the pivoting the below table.

Current Result by the Query :

SELECT     Genset_Master.EngNo, Genset_Master.AltNo, Genset_Master.CustName, Service_Master.SiteAdd, 
                      Servicing_History.ServDate
FROM         Service_Master INNER JOIN
                      Genset_Master ON Service_Master.Genset_Id = Genset_Master.Genset_Id INNER JOIN
                      Servicing_History ON Service_Master.Genset_Id = Servicing_History.Genset_Id 

==========

EngNo  AltNo   CustName   SiteAdd        ServDate
————– — ————----------------------------------------
001       Alt1       Cust1         Site1          2007-03-06
001       Alt1       Cust1         Site1          2007-05-11
002       Alt2       Cust2         Site2          2007-08-05
002       Alt2       Cust2         Site2          2007-08-12



I want the result in below format

EngNo AltNo CustName SiteAdd ServDate1 ServDate 2 
— ————----------------------------------------------------------
001     Alt1    Cust1       Site1      2007-03-06   2007-03-11
002     Alt2    Cust2       Site2      2007-08-05   2007-08-12

Please guide me to create query for above result]]></description>
		<content:encoded><![CDATA[<p>Hi All,</p>
<p>I too need the pivoting the below table.</p>
<p>Current Result by the Query :</p>
<p>SELECT     Genset_Master.EngNo, Genset_Master.AltNo, Genset_Master.CustName, Service_Master.SiteAdd,<br />
                      Servicing_History.ServDate<br />
FROM         Service_Master INNER JOIN<br />
                      Genset_Master ON Service_Master.Genset_Id = Genset_Master.Genset_Id INNER JOIN<br />
                      Servicing_History ON Service_Master.Genset_Id = Servicing_History.Genset_Id </p>
<p>==========</p>
<p>EngNo  AltNo   CustName   SiteAdd        ServDate<br />
————– — ————&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
001       Alt1       Cust1         Site1          2007-03-06<br />
001       Alt1       Cust1         Site1          2007-05-11<br />
002       Alt2       Cust2         Site2          2007-08-05<br />
002       Alt2       Cust2         Site2          2007-08-12</p>
<p>I want the result in below format</p>
<p>EngNo AltNo CustName SiteAdd ServDate1 ServDate 2<br />
— ————&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
001     Alt1    Cust1       Site1      2007-03-06   2007-03-11<br />
002     Alt2    Cust2       Site2      2007-08-05   2007-08-12</p>
<p>Please guide me to create query for above result</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manivannan</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-61221</link>
		<dc:creator><![CDATA[Manivannan]]></dc:creator>
		<pubDate>Tue, 16 Feb 2010 07:16:01 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-61221</guid>
		<description><![CDATA[Hi... I have a Question.. How to write a query for following task..

INPUT

Name ENG TAM MAT
--------------------------
RAJ      52  65  72
RAM     45  98  75
JOHN    78  88 52

I want the output as

Name  RAM
-----------------
ENG      45
TAM       98
MAT       75
    

Can anyone help me..???]]></description>
		<content:encoded><![CDATA[<p>Hi&#8230; I have a Question.. How to write a query for following task..</p>
<p>INPUT</p>
<p>Name ENG TAM MAT<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
RAJ      52  65  72<br />
RAM     45  98  75<br />
JOHN    78  88 52</p>
<p>I want the output as</p>
<p>Name  RAM<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
ENG      45<br />
TAM       98<br />
MAT       75</p>
<p>Can anyone help me..???</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roberto</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-59369</link>
		<dc:creator><![CDATA[Roberto]]></dc:creator>
		<pubDate>Tue, 05 Jan 2010 17:35:24 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-59369</guid>
		<description><![CDATA[Thanks Imran 

Your Script saved me sooo much time.

Truly appreciated.]]></description>
		<content:encoded><![CDATA[<p>Thanks Imran </p>
<p>Your Script saved me sooo much time.</p>
<p>Truly appreciated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kajal Shah</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-59139</link>
		<dc:creator><![CDATA[Kajal Shah]]></dc:creator>
		<pubDate>Wed, 30 Dec 2009 13:08:01 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-59139</guid>
		<description><![CDATA[Hi,

How can i do the Pivoting in SQL Server 2000.
any suggesion or reference link is appreciable.

Thanks in advance]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>How can i do the Pivoting in SQL Server 2000.<br />
any suggesion or reference link is appreciable.</p>
<p>Thanks in advance</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Max</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-58661</link>
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Tue, 15 Dec 2009 14:35:16 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-58661</guid>
		<description><![CDATA[Yeah, pivoting tables are fine and dandy, but when it comes to reporting, (And this is the only case I really needed pivot), most of the reporting tools can not deal with pivots or can not handle unknown number of columns in output data.. etc. 
So I had to make up other solutions...]]></description>
		<content:encoded><![CDATA[<p>Yeah, pivoting tables are fine and dandy, but when it comes to reporting, (And this is the only case I really needed pivot), most of the reporting tools can not deal with pivots or can not handle unknown number of columns in output data.. etc.<br />
So I had to make up other solutions&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alice Hsu</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-57978</link>
		<dc:creator><![CDATA[Alice Hsu]]></dc:creator>
		<pubDate>Sun, 29 Nov 2009 02:42:40 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-57978</guid>
		<description><![CDATA[VendorName                       CostCenter   DT            Amount
ANCHOR SAFETY INC	91401	5/9/2009 	22.58
ANCHOR SAFETY INC	91401	7/9/2009 	63.38
AMERICAN TOWER                   91442	6/9/2009 	18.7
AMERICAN TOWER  	                91442	8/9/2009 	19.19

If I have the data as above and I like to get the following result:

ANCHOR SAFETY INC 91401 5/9/2009 28.58 7/9/2009 63.38
AMERICAN TOWER     91442 6/9/2009 18.7 8/9/2009 19.19

I tried to use PIVOT in SQL Server 2005 but failed.

Please help.

Thank you.]]></description>
		<content:encoded><![CDATA[<p>VendorName                       CostCenter   DT            Amount<br />
ANCHOR SAFETY INC	91401	5/9/2009 	22.58<br />
ANCHOR SAFETY INC	91401	7/9/2009 	63.38<br />
AMERICAN TOWER                   91442	6/9/2009 	18.7<br />
AMERICAN TOWER  	                91442	8/9/2009 	19.19</p>
<p>If I have the data as above and I like to get the following result:</p>
<p>ANCHOR SAFETY INC 91401 5/9/2009 28.58 7/9/2009 63.38<br />
AMERICAN TOWER     91442 6/9/2009 18.7 8/9/2009 19.19</p>
<p>I tried to use PIVOT in SQL Server 2005 but failed.</p>
<p>Please help.</p>
<p>Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-56197</link>
		<dc:creator><![CDATA[Imran Mohammed]]></dc:creator>
		<pubDate>Sun, 27 Sep 2009 06:00:11 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-56197</guid>
		<description><![CDATA[@Rahul. 

I need more information for your input and output, your output is confusing, please post complete output. 

Here is a sample script. 
SELECT ITEM_TYPE, [1], [2], [3], [4], [5], [6], [7] 
FROM 
(SELECT ITEM_TYPE, QTY , QTY AS QTYY
FROM Example4) p
PIVOT
(
MAX (QTYY)
FOR QTY IN
( [1], [2], [3], [4], [5], [6], [7] )
) AS pvt
ORDER BY VendorID;

What I see from your procedure, we can do it through another procedure or script with a while loop, I dont know if that could be done through a simple select statement. 

~ IM.]]></description>
		<content:encoded><![CDATA[<p>@Rahul. </p>
<p>I need more information for your input and output, your output is confusing, please post complete output. </p>
<p>Here is a sample script.<br />
SELECT ITEM_TYPE, [1], [2], [3], [4], [5], [6], [7]<br />
FROM<br />
(SELECT ITEM_TYPE, QTY , QTY AS QTYY<br />
FROM Example4) p<br />
PIVOT<br />
(<br />
MAX (QTYY)<br />
FOR QTY IN<br />
( [1], [2], [3], [4], [5], [6], [7] )<br />
) AS pvt<br />
ORDER BY VendorID;</p>
<p>What I see from your procedure, we can do it through another procedure or script with a while loop, I dont know if that could be done through a simple select statement. </p>
<p>~ IM.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-56196</link>
		<dc:creator><![CDATA[Imran Mohammed]]></dc:creator>
		<pubDate>Sun, 27 Sep 2009 05:48:14 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-56196</guid>
		<description><![CDATA[@Gary,

Why don&#039;t you make a computed column in your select list, with what ever expression you have and then name that column , and then in pivot, just use max expression. 

Just give us some sample data, input, and expected output. 

~ IM.]]></description>
		<content:encoded><![CDATA[<p>@Gary,</p>
<p>Why don&#8217;t you make a computed column in your select list, with what ever expression you have and then name that column , and then in pivot, just use max expression. </p>
<p>Just give us some sample data, input, and expected output. </p>
<p>~ IM.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-56195</link>
		<dc:creator><![CDATA[Imran Mohammed]]></dc:creator>
		<pubDate>Sun, 27 Sep 2009 05:43:54 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-56195</guid>
		<description><![CDATA[@Peter 

create table #Example ([PARAM] varchar (40), [VALUE]  varchar (40))

insert into #Example  values (&#039;k4401&#039;, &#039;AAA&#039;)
insert into #Example  values (&#039;k4402&#039;, &#039;BBB&#039;)
insert into #Example  values (&#039;k4403&#039;, &#039;CCC&#039;)

SELECT [k4401], [k4402], [k4403]
FROM 
(SELECT [PARAM], [VALUE]
FROM #Example) p
PIVOT
(
MAX ([VALUE])
FOR [PARAM] IN
( [k4401], [k4402], [k4403])
) AS pvt


~ IM]]></description>
		<content:encoded><![CDATA[<p>@Peter </p>
<p>create table #Example ([PARAM] varchar (40), [VALUE]  varchar (40))</p>
<p>insert into #Example  values (&#8216;k4401&#8242;, &#8216;AAA&#8217;)<br />
insert into #Example  values (&#8216;k4402&#8242;, &#8216;BBB&#8217;)<br />
insert into #Example  values (&#8216;k4403&#8242;, &#8216;CCC&#8217;)</p>
<p>SELECT [k4401], [k4402], [k4403]<br />
FROM<br />
(SELECT [PARAM], [VALUE]<br />
FROM #Example) p<br />
PIVOT<br />
(<br />
MAX ([VALUE])<br />
FOR [PARAM] IN<br />
( [k4401], [k4402], [k4403])<br />
) AS pvt</p>
<p>~ IM</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-56192</link>
		<dc:creator><![CDATA[Peter]]></dc:creator>
		<pubDate>Sat, 26 Sep 2009 22:15:07 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-56192</guid>
		<description><![CDATA[sorry for that post: to keep it short;

table: 

PARAM	VALUE
k4401	AAA
k4402	BBB
k4403	CCC

Output would look like:

k4401      k4402	k4403
AAA	BBB	CCC


thanks in advance]]></description>
		<content:encoded><![CDATA[<p>sorry for that post: to keep it short;</p>
<p>table: </p>
<p>PARAM	VALUE<br />
k4401	AAA<br />
k4402	BBB<br />
k4403	CCC</p>
<p>Output would look like:</p>
<p>k4401      k4402	k4403<br />
AAA	BBB	CCC</p>
<p>thanks in advance</p>
]]></content:encoded>
	</item>
</channel>
</rss>

