SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Trying to use PIVOT
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kishor86.samant
Starting Member

India
1 Posts

Posted - 11/08/2012 :  07:48:37  Show Profile  Reply with Quote
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

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

sunitabeck
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: http://beyondrelational.com/modules/2/blogs/70/posts/10791/dynamic-crosstab-with-multiple-pivot-columns.aspx
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.12 seconds. Powered By: Snitz Forums 2000