<?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>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-56197</link>
		<dc:creator>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>@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>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>@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>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>@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>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>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>
	<item>
		<title>By: Gary</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-56189</link>
		<dc:creator>Gary</dc:creator>
		<pubDate>Sat, 26 Sep 2009 15:23:19 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-56189</guid>
		<description>Hi, Pinal, Robin

Any further words on using two aggreations in the PIVOT? 
Or is it possible to use an expression in the place of aggreation function? something like  (SUM(SellAmount) - SUM(CostAmount))/SUM(SellAmount)*100,
instead of a single native function.

thanks a lot</description>
		<content:encoded><![CDATA[<p>Hi, Pinal, Robin</p>
<p>Any further words on using two aggreations in the PIVOT?<br />
Or is it possible to use an expression in the place of aggreation function? something like  (SUM(SellAmount) &#8211; SUM(CostAmount))/SUM(SellAmount)*100,<br />
instead of a single native function.</p>
<p>thanks a lot</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: RAHUL</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-56149</link>
		<dc:creator>RAHUL</dc:creator>
		<pubDate>Fri, 25 Sep 2009 04:05:12 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-56149</guid>
		<description>Hello,

I have a table ITEM_MST

ITEM_TYPE     QTY       Date
1                   2           15 July 2009
1                   4           16 July 2009
2                    3          17 July 2009
2                   1           18 July 2009
1                   4           19 July 2009
1                   6           20 July 2009
1                    2          21 July 2009

I wan the output in this format

ITEM_TYPE      QTY1         QTY2      QTY3
1                      2              4           4
1                      6               2
2                      3              1

I dont want to use any aggregate functions as there is nothing to aggregate.

Please let me know the solution for the same ASAP.

Thanks and Regards
Rahul</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I have a table ITEM_MST</p>
<p>ITEM_TYPE     QTY       Date<br />
1                   2           15 July 2009<br />
1                   4           16 July 2009<br />
2                    3          17 July 2009<br />
2                   1           18 July 2009<br />
1                   4           19 July 2009<br />
1                   6           20 July 2009<br />
1                    2          21 July 2009</p>
<p>I wan the output in this format</p>
<p>ITEM_TYPE      QTY1         QTY2      QTY3<br />
1                      2              4           4<br />
1                      6               2<br />
2                      3              1</p>
<p>I dont want to use any aggregate functions as there is nothing to aggregate.</p>
<p>Please let me know the solution for the same ASAP.</p>
<p>Thanks and Regards<br />
Rahul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mostafiz</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-53943</link>
		<dc:creator>mostafiz</dc:creator>
		<pubDate>Wed, 22 Jul 2009 07:13:43 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-53943</guid>
		<description>Suppose , Table Sales has 10 product ,I want to Top 5 Sales product 
 and sum of the rest  of  product in  single select Query</description>
		<content:encoded><![CDATA[<p>Suppose , Table Sales has 10 product ,I want to Top 5 Sales product<br />
 and sum of the rest  of  product in  single select Query</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-52657</link>
		<dc:creator>Imran Mohammed</dc:creator>
		<pubDate>Tue, 02 Jun 2009 15:45:40 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-52657</guid>
		<description>@Mahdestiny, 

Then you need to write Dynamic SQL.

First prepare the select statement with Dynamic SQL. 

Once you prepare the select statement, then execute that statement. 


~ IM.</description>
		<content:encoded><![CDATA[<p>@Mahdestiny, </p>
<p>Then you need to write Dynamic SQL.</p>
<p>First prepare the select statement with Dynamic SQL. </p>
<p>Once you prepare the select statement, then execute that statement. </p>
<p>~ IM.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mahdestiny</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-52637</link>
		<dc:creator>Mahdestiny</dc:creator>
		<pubDate>Tue, 02 Jun 2009 06:53:22 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-52637</guid>
		<description>Here your using 

&quot;SELECT [No] , [ID] ,[05/01/2009] ,[05/15/2009] ,[05/20/2009] ,[06/01/2009]
FROM ( &quot;

i cant say how many dates will be coming from select statement. 
coz im using Select * from T1, this will return me many Date.
Also im not using sum([Value]) FOR [Date] wise. 
I need to show dynamically date as column and value as row using pivot.</description>
		<content:encoded><![CDATA[<p>Here your using </p>
<p>&#8220;SELECT [No] , [ID] ,[05/01/2009] ,[05/15/2009] ,[05/20/2009] ,[06/01/2009]<br />
FROM ( &#8221;</p>
<p>i cant say how many dates will be coming from select statement.<br />
coz im using Select * from T1, this will return me many Date.<br />
Also im not using sum([Value]) FOR [Date] wise.<br />
I need to show dynamically date as column and value as row using pivot.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Imran Mohammed</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-52623</link>
		<dc:creator>Imran Mohammed</dc:creator>
		<pubDate>Tue, 02 Jun 2009 01:26:17 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-52623</guid>
		<description>@Mahdestiny

This is the script.

-- Create Table
create table T1 ( [No] int,  [ID] int, Date Datetime, Value decimal (38,2))

-- Insert data into the table
insert into T1 values (1, 1001, &#039;05/01/2009&#039;, 101.00)
insert into T1 values (1, 1001, &#039;05/15/2009&#039;, 102.00)
insert into T1 values (1, 1001, &#039;05/20/2009&#039;, 105.00)
insert into T1 values (2, 1001, &#039;05/01/2009&#039;, 41.00)
insert into T1 values (2, 1001, &#039;05/15/2009&#039;, 44.00)
insert into T1 values (3, 1001, &#039;06/01/2009&#039;, 330.00)

-- Check the Data
select * from  T1

-- Using Pivot key word to get required output
SELECT [No] , [ID] ,[05/01/2009] ,[05/15/2009] ,[05/20/2009] ,[06/01/2009]
FROM (
SELECT [No], [ID], [Date], [Value]
FROM T1) up
PIVOT ( sum([Value]) FOR [Date] in ([05/01/2009] ,[05/15/2009] ,[05/20/2009] ,[06/01/2009]) )AS pvt


~ IM.</description>
		<content:encoded><![CDATA[<p>@Mahdestiny</p>
<p>This is the script.</p>
<p>&#8211; Create Table<br />
create table T1 ( [No] int,  [ID] int, Date Datetime, Value decimal (38,2))</p>
<p>&#8211; Insert data into the table<br />
insert into T1 values (1, 1001, &#8216;05/01/2009&#8242;, 101.00)<br />
insert into T1 values (1, 1001, &#8216;05/15/2009&#8242;, 102.00)<br />
insert into T1 values (1, 1001, &#8216;05/20/2009&#8242;, 105.00)<br />
insert into T1 values (2, 1001, &#8216;05/01/2009&#8242;, 41.00)<br />
insert into T1 values (2, 1001, &#8216;05/15/2009&#8242;, 44.00)<br />
insert into T1 values (3, 1001, &#8216;06/01/2009&#8242;, 330.00)</p>
<p>&#8211; Check the Data<br />
select * from  T1</p>
<p>&#8211; Using Pivot key word to get required output<br />
SELECT [No] , [ID] ,[05/01/2009] ,[05/15/2009] ,[05/20/2009] ,[06/01/2009]<br />
FROM (<br />
SELECT [No], [ID], [Date], [Value]<br />
FROM T1) up<br />
PIVOT ( sum([Value]) FOR [Date] in ([05/01/2009] ,[05/15/2009] ,[05/20/2009] ,[06/01/2009]) )AS pvt</p>
<p>~ IM.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mahdestiny</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-52608</link>
		<dc:creator>Mahdestiny</dc:creator>
		<pubDate>Mon, 01 Jun 2009 12:05:50 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-52608</guid>
		<description>Hi...
I have a table : T1

No      ID            Date                Value
___________________________________
1	1001	01/05/2009	101.00
1	1001	15/05/2009	102.00
1	1001	20/05/2009	105.00
2	1001	01/05/2009	41.00
2	1001	15/05/2009	44.00
3	1001	01/06/2009	330.00

I need the Data in this Format

No     ID       01/05/2009   15/05/2009   20/05/2009   
01/06/2009
____________________________________________________

1     1001     101.00            102.00           105.00     NULL
2     1001     41.00              44.00             NULL        NULL 
3     1001     NULL               NULL              NULL       330.00

can you give me the solution for this type...

Thanks in advance</description>
		<content:encoded><![CDATA[<p>Hi&#8230;<br />
I have a table : T1</p>
<p>No      ID            Date                Value<br />
___________________________________<br />
1	1001	01/05/2009	101.00<br />
1	1001	15/05/2009	102.00<br />
1	1001	20/05/2009	105.00<br />
2	1001	01/05/2009	41.00<br />
2	1001	15/05/2009	44.00<br />
3	1001	01/06/2009	330.00</p>
<p>I need the Data in this Format</p>
<p>No     ID       01/05/2009   15/05/2009   20/05/2009<br />
01/06/2009<br />
____________________________________________________</p>
<p>1     1001     101.00            102.00           105.00     NULL<br />
2     1001     41.00              44.00             NULL        NULL<br />
3     1001     NULL               NULL              NULL       330.00</p>
<p>can you give me the solution for this type&#8230;</p>
<p>Thanks in advance</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sreedhar</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-50948</link>
		<dc:creator>Sreedhar</dc:creator>
		<pubDate>Tue, 14 Apr 2009 05:39:36 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-50948</guid>
		<description>THis is related to above question. I can move the table to sql if needed. If I know I can get it easier from there.

THanks,
Sreedhar</description>
		<content:encoded><![CDATA[<p>THis is related to above question. I can move the table to sql if needed. If I know I can get it easier from there.</p>
<p>THanks,<br />
Sreedhar</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sreedhar</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-50947</link>
		<dc:creator>Sreedhar</dc:creator>
		<pubDate>Tue, 14 Apr 2009 05:38:14 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-50947</guid>
		<description>Hi Pinal,
You&#039;re examples on pivot and unpivot are very good. However I have some questions which may or may not have to use this. Please suggest with your experience which is suitable for me.

I have a TABLE in oracle as

 Australia   Entry1  Apple     $ 2 
Japan         Entry2 Guava    $2 
Australia    Entry2  Guava   $2 
Hungary    Entry3  Guava   $2 
Australia   Entry2  Apple    $2 
Japan       Entry1  Guava    $2 
Australia   Entry4  Orange  $2 
Japan        Entry2  Orange $2 


My Output should be as follows where Amount is added w.r.t Entries as well as Fruits but in columns.

Country Entry1 Entry2 Entry3 Entry4 Apple Guava Orange

Australias  $2      $4         0         $2      $4     $2        $2    

Japan        $2       $4        0          0        0       $4      $2

 Hungary    0          0        $2        0        0        $2       0

I would like the output as above. However I do not want to use decode, which is what I am using right now.

Is it possible to use this for a varible number of columns. Basically the number of columns will not be more than 10 for sure, but I need them to be variable which is not possible by using decode.

Thanks for all your help.
Sreedhar</description>
		<content:encoded><![CDATA[<p>Hi Pinal,<br />
You&#8217;re examples on pivot and unpivot are very good. However I have some questions which may or may not have to use this. Please suggest with your experience which is suitable for me.</p>
<p>I have a TABLE in oracle as</p>
<p> Australia   Entry1  Apple     $ 2<br />
Japan         Entry2 Guava    $2<br />
Australia    Entry2  Guava   $2<br />
Hungary    Entry3  Guava   $2<br />
Australia   Entry2  Apple    $2<br />
Japan       Entry1  Guava    $2<br />
Australia   Entry4  Orange  $2<br />
Japan        Entry2  Orange $2 </p>
<p>My Output should be as follows where Amount is added w.r.t Entries as well as Fruits but in columns.</p>
<p>Country Entry1 Entry2 Entry3 Entry4 Apple Guava Orange</p>
<p>Australias  $2      $4         0         $2      $4     $2        $2    </p>
<p>Japan        $2       $4        0          0        0       $4      $2</p>
<p> Hungary    0          0        $2        0        0        $2       0</p>
<p>I would like the output as above. However I do not want to use decode, which is what I am using right now.</p>
<p>Is it possible to use this for a varible number of columns. Basically the number of columns will not be more than 10 for sure, but I need them to be variable which is not possible by using decode.</p>
<p>Thanks for all your help.<br />
Sreedhar</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kabil</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-50016</link>
		<dc:creator>kabil</dc:creator>
		<pubDate>Thu, 26 Mar 2009 09:42:47 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-50016</guid>
		<description>hi..i ve written one query it return the following results

date         [name]
06:00       aaaa
06:00       bbbb
06:00       ccccc
06:30       dddd
06:30       eeee
06:30       ffffffff
06:30       gggg
07:00       hhhh
08:00       NULL
08:30       NULL
09:00       NULL
09:30       IIIIII
10:00       NULL
.
.
..
i want to display this in the following format

date     name
06:00   aaaa  bbbb  cccc    NULL
06:30   dddd  eeee  ffffff    gggg
07:00   hhhh  NULL  NULL  NULL
08:30   NULL  NULL  NULL  NULL
09:00   NULL  NULL  NULL  NULL
10:00   IIIIII  NULL  NULL  NULL
.
.
.
.
is it possible using pivot? kindly help me</description>
		<content:encoded><![CDATA[<p>hi..i ve written one query it return the following results</p>
<p>date         [name]<br />
06:00       aaaa<br />
06:00       bbbb<br />
06:00       ccccc<br />
06:30       dddd<br />
06:30       eeee<br />
06:30       ffffffff<br />
06:30       gggg<br />
07:00       hhhh<br />
08:00       NULL<br />
08:30       NULL<br />
09:00       NULL<br />
09:30       IIIIII<br />
10:00       NULL<br />
.<br />
.<br />
..<br />
i want to display this in the following format</p>
<p>date     name<br />
06:00   aaaa  bbbb  cccc    NULL<br />
06:30   dddd  eeee  ffffff    gggg<br />
07:00   hhhh  NULL  NULL  NULL<br />
08:30   NULL  NULL  NULL  NULL<br />
09:00   NULL  NULL  NULL  NULL<br />
10:00   IIIIII  NULL  NULL  NULL<br />
.<br />
.<br />
.<br />
.<br />
is it possible using pivot? kindly help me</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xomaly</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-48762</link>
		<dc:creator>xomaly</dc:creator>
		<pubDate>Wed, 11 Mar 2009 20:19:10 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-48762</guid>
		<description>THANK YOU 
YOU FINALLY SOLVE MY DOUBTS 
THANK YOU VERY MUCH</description>
		<content:encoded><![CDATA[<p>THANK YOU<br />
YOU FINALLY SOLVE MY DOUBTS<br />
THANK YOU VERY MUCH</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Tkatch</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-48733</link>
		<dc:creator>Brian Tkatch</dc:creator>
		<pubDate>Wed, 11 Mar 2009 14:25:45 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-48733</guid>
		<description>@xomaly i do not understand your question. So, i guessed. How about this:

WITH
		Data
AS
		(
		 SELECT 401 d, 0.3 a, 0.8 b, 0.9 c, &#039;z&#039; a1, &#039;x&#039; b2, &#039;y&#039; c3 UNION ALL
		 SELECT 402 d, 0.4 a, 0.5 b, 0.6 c, &#039;x&#039; a1, &#039;z&#039; b2, &#039;y&#039; c3
		)
SELECT
		d,
		CASE a1
		 WHEN &#039;z&#039; THEN a
		 WHEN &#039;X&#039; THEN b
		 WHEN &#039;y&#039; THEN c
		END,
		CASE b2
		 WHEN &#039;z&#039; THEN a
		 WHEN &#039;X&#039; THEN b
		 WHEN &#039;y&#039; THEN c
		END,
		CASE c3
		 WHEN &#039;z&#039; THEN a
		 WHEN &#039;X&#039; THEN b
		 WHEN &#039;y&#039; THEN c
		END
FROM
		Data;</description>
		<content:encoded><![CDATA[<p>@xomaly i do not understand your question. So, i guessed. How about this:</p>
<p>WITH<br />
		Data<br />
AS<br />
		(<br />
		 SELECT 401 d, 0.3 a, 0.8 b, 0.9 c, &#8216;z&#8217; a1, &#8216;x&#8217; b2, &#8216;y&#8217; c3 UNION ALL<br />
		 SELECT 402 d, 0.4 a, 0.5 b, 0.6 c, &#8216;x&#8217; a1, &#8216;z&#8217; b2, &#8216;y&#8217; c3<br />
		)<br />
SELECT<br />
		d,<br />
		CASE a1<br />
		 WHEN &#8216;z&#8217; THEN a<br />
		 WHEN &#8216;X&#8217; THEN b<br />
		 WHEN &#8216;y&#8217; THEN c<br />
		END,<br />
		CASE b2<br />
		 WHEN &#8216;z&#8217; THEN a<br />
		 WHEN &#8216;X&#8217; THEN b<br />
		 WHEN &#8216;y&#8217; THEN c<br />
		END,<br />
		CASE c3<br />
		 WHEN &#8216;z&#8217; THEN a<br />
		 WHEN &#8216;X&#8217; THEN b<br />
		 WHEN &#8216;y&#8217; THEN c<br />
		END<br />
FROM<br />
		Data;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xomaly</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-48650</link>
		<dc:creator>xomaly</dc:creator>
		<pubDate>Tue, 10 Mar 2009 21:40:13 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-48650</guid>
		<description>Hi PLS HELP ME, i have a table like that

d	a	b	c	a1	b2    c3
401	0.3	0.8	0.9	z	x       y
402	0.4	0.5	0.6	x	z       y
	
And i need this result in my query
   d              z             x                 y	
401	0.3	0.8	0.9			
402	0.5	0.4	0.6	

I was thinking on pivot tables but i dont know how to do it with more colums</description>
		<content:encoded><![CDATA[<p>Hi PLS HELP ME, i have a table like that</p>
<p>d	a	b	c	a1	b2    c3<br />
401	0.3	0.8	0.9	z	x       y<br />
402	0.4	0.5	0.6	x	z       y</p>
<p>And i need this result in my query<br />
   d              z             x                 y<br />
401	0.3	0.8	0.9<br />
402	0.5	0.4	0.6	</p>
<p>I was thinking on pivot tables but i dont know how to do it with more colums</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - PIVOT and UNPIVOT Table Examples Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-47351</link>
		<dc:creator>SQL SERVER - PIVOT and UNPIVOT Table Examples Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Wed, 25 Feb 2009 11:23:51 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-47351</guid>
		<description>[...] Reference : Pinal Dave (http://blog.SQLAuthority.com), SQL SERVER - UNPIVOT Table Example, SQL SERVER - PIVOT Table Example [...]</description>
		<content:encoded><![CDATA[<p>[...] Reference : Pinal Dave (<a href="http://blog.SQLAuthority.com)" rel="nofollow">http://blog.SQLAuthority.com)</a>, SQL SERVER &#8211; UNPIVOT Table Example, SQL SERVER &#8211; PIVOT Table Example [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aaron</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-46342</link>
		<dc:creator>aaron</dc:creator>
		<pubDate>Thu, 05 Feb 2009 01:48:14 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-46342</guid>
		<description>(continue last post)

The challenge is that MV value could be any string, could be V1 ~ Vx. And for Same MV value, they just want to list all dates, like

SiteNo   SubNo       [V1]      [V1]   [V1]    [V2]         [V3]         [V4]         [V5]          [V6]
------   ---------   -----------   ---------   ----------   -----------  -----------   ----------  ------------  ----------------
001      SUB-028     2007-03-11   2007-03-15    2007-03-19    2007-05-21   2007-06-22   2007-07-11   2007-08-05   2007-09-28</description>
		<content:encoded><![CDATA[<p>(continue last post)</p>
<p>The challenge is that MV value could be any string, could be V1 ~ Vx. And for Same MV value, they just want to list all dates, like</p>
<p>SiteNo   SubNo       [V1]      [V1]   [V1]    [V2]         [V3]         [V4]         [V5]          [V6]<br />
&#8212;&#8212;   &#8212;&#8212;&#8212;   &#8212;&#8212;&#8212;&#8211;   &#8212;&#8212;&#8212;   &#8212;&#8212;&#8212;-   &#8212;&#8212;&#8212;&#8211;  &#8212;&#8212;&#8212;&#8211;   &#8212;&#8212;&#8212;-  &#8212;&#8212;&#8212;&#8212;  &#8212;&#8212;&#8212;&#8212;&#8212;-<br />
001      SUB-028     2007-03-11   2007-03-15    2007-03-19    2007-05-21   2007-06-22   2007-07-11   2007-08-05   2007-09-28</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aaron</title>
		<link>http://blog.sqlauthority.com/2008/05/22/sql-server-pivot-table-example/#comment-46341</link>
		<dc:creator>aaron</dc:creator>
		<pubDate>Thu, 05 Feb 2009 01:34:05 +0000</pubDate>
		<guid isPermaLink="false">http://sqlauthority.wordpress.com/?p=612#comment-46341</guid>
		<description>Hi *Imran Mohammed*, it&#039;s so great you worked it right. I was struggling on what function should be used too. Yes, in the case I posted, it works perfectly. 
As you already see that actually I do have case like below, which for one MV value there’re more than one dates. I wonder if this can be done by PIVOT. If not, any other option?

SiteNo   SubNo       MV     Date
------       --------        ---      ------------
001      SUB-028     V1     2007-03-11
001      SUB-028     V1     2007-03-15
001      SUB-028     V1     2007-03-19
001      SUB-028     V2     2007-05-21
001      SUB-028     V3     2007-06-22
001      SUB-028     V4     2007-07-11
001      SUB-028     V4     2007-07-17
001      SUB-028     V4     2007-07-21
001      SUB-028     V4     2007-07-29
001      SUB-028     V5     2007-08-05
001      SUB-028     V6     2007-09-28
002      SUB-010     V1     2007-04-22
002      SUB-010     V2     2007-05-22
002      SUB-010     V3     2007-06-05
002      SUB-010     V3     2007-07-05</description>
		<content:encoded><![CDATA[<p>Hi *Imran Mohammed*, it&#8217;s so great you worked it right. I was struggling on what function should be used too. Yes, in the case I posted, it works perfectly.<br />
As you already see that actually I do have case like below, which for one MV value there’re more than one dates. I wonder if this can be done by PIVOT. If not, any other option?</p>
<p>SiteNo   SubNo       MV     Date<br />
&#8212;&#8212;       &#8212;&#8212;&#8211;        &#8212;      &#8212;&#8212;&#8212;&#8212;<br />
001      SUB-028     V1     2007-03-11<br />
001      SUB-028     V1     2007-03-15<br />
001      SUB-028     V1     2007-03-19<br />
001      SUB-028     V2     2007-05-21<br />
001      SUB-028     V3     2007-06-22<br />
001      SUB-028     V4     2007-07-11<br />
001      SUB-028     V4     2007-07-17<br />
001      SUB-028     V4     2007-07-21<br />
001      SUB-028     V4     2007-07-29<br />
001      SUB-028     V5     2007-08-05<br />
001      SUB-028     V6     2007-09-28<br />
002      SUB-010     V1     2007-04-22<br />
002      SUB-010     V2     2007-05-22<br />
002      SUB-010     V3     2007-06-05<br />
002      SUB-010     V3     2007-07-05</p>
]]></content:encoded>
	</item>
</channel>
</rss>
