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
 Looking for the solution

Author  Topic 

venkachi
Starting Member

1 Post

Posted - 2013-04-17 : 04:07:13
actually my table data is

Key value
firstname surya
firstname rakhi
firstname venkat
firstname shankar
firstname dany

I want to disply like
firstname
surya
rakhi
venkat
shankar
dany


i write the below query

SELECT firstname
FROM test pvt
PIVOT (MAX(pvt.value ) FOR pvt.key1 IN (firstname)) AS P

but it showing

firstname
venkat


Please help to solve this

satheesh
Posting Yak Master

152 Posts

Posted - 2013-04-17 : 05:45:14
Please have a look at the post
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=150223

Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-04-18 : 02:36:49
you can give field like that inside PIVOT

you need to use dynamic sql in PIVOT if you want values to be taken from a field.

http://beyondrelational.com/modules/2/blogs/70/posts/10840/dynamic-pivot-in-sql-server-2005.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -