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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Trying to use PIVOT

Author  Topic 

kishor86.samant
Starting Member

1 Post

Posted - 2012-11-08 : 07:48:37
Hi,

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

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-08 : 08:28:23
Sounds like you will need to use dynamic pivot. See Madhivanan's blog here - it has code and examples: http://beyondrelational.com/modules/2/blogs/70/posts/10791/dynamic-crosstab-with-multiple-pivot-columns.aspx
Go to Top of Page
   

- Advertisement -