Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 alternative of pivot query
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

230 Posts

Posted - 02/01/2013 :  14:09:05  Show Profile  Reply with Quote
I have a query similar to below

select type, A, B, C, D, E
(select type, organisation
from table1) as r
select sum(price)
for organisation in ([A], [B], [C], [D], [E])
) as sumofpivot

The values of column "organisation" keeps changing and so I have to again and again modify the code to include the new columns.

Is there anyway to add new columns automatically based on the values of column organisation and keep updating ?

Edited by - learning_grsql on 02/01/2013 14:10:13

Flowing Fount of Yak Knowledge

6065 Posts

Posted - 02/01/2013 :  16:48:36  Show Profile  Reply with Quote
You would need to use a dynamic solution. Search this site for dynamic cross tab or dynamic pivot.
Here's one example:

Be One with the Optimizer
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 02/02/2013 :  03:10:41  Show Profile  Reply with Quote

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000