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
 need help in query

Author  Topic 

sur200
Starting Member

7 Posts

Posted - 2013-03-04 : 05:02:59
create table temp(id integer, comments varchar(20), custom_id integer);

insert into temp values(1,'CEO comments', 98)
insert into temp values(2,'SEO comments', 99)
insert into temp values(3,'X comments', 100)
insert into temp values(1,'SEO comments', 99)

want output like
id CEO_Comments SEO_Comments _ExtraComments
1 Ceo comments seo comments Null
2 null seo comments null
3. null null x comments


any idea?

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-04 : 05:20:24
[code]
SELECT id,
MAX(CASE WHEN comments = 'CEO comments' THEN comments END) AS CEO_comments,
MAX(CASE WHEN comments = 'SEO comments' THEN comments END) AS SEO_comments,
MAX(CASE WHEN comments = 'X comments' THEN comments END) AS Extra_comments
FROM table
GROUP BY id
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -