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
 need help in query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sur200
Starting Member

India
7 Posts

Posted - 03/04/2013 :  05:02:59  Show Profile  Reply with Quote
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

India
52317 Posts

Posted - 03/04/2013 :  05:20:24  Show Profile  Reply with Quote

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


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

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.06 seconds. Powered By: Snitz Forums 2000