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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 need help in query
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

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?


Very Important crosS Applying yaK Herder

52326 Posts

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

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 

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next 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.04 seconds. Powered By: Snitz Forums 2000