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
 Trying to use PIVOT
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 11/08/2012 :  07:48:37  Show Profile  Reply with Quote

I have a table like,

Officer_Id Data_Point Data_Point_Value
1 A bhj
1 B dgsdf
1 C bdfbh

I want to get result like,

Officer_Id A B C
1 bhj dgsdf bdfbh

How to achieve it? I tried to use Pivot operator in following way,

select * from pivot_test t
pivot( max(Data_Point_Value) for t.Data_Point in ([A],[B],[C]) ) pv

It works.
But while querying i am not aware of all data points (i.e. A, B, C).
How to say pivot( max(Data_Point_Value) for t.Data_Point in (*) )

Please help.

Thanks in advance,
Kishor Samant

Edited by - kishor86.samant on 11/08/2012 08:08:38

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/08/2012 :  08:28:23  Show Profile  Reply with Quote
Sounds like you will need to use dynamic pivot. See Madhivanan's blog here - it has code and examples:
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.03 seconds. Powered By: Snitz Forums 2000