Help with query

  • create table DNS (id int, dns varchar(50), orderid int)

    GO

    insert into DNS values (5001, 'dev.net', 1);

    insert into DNS values (5001, 'QA.net', 2);

    insert into DNS values (5001, 'Test.net', 3);

    select * from DNS gives me data looks like:

    iddnsorderid

    5001dev.net1

    5001QA.net2

    5001Test.net3

    I want to have data which looks like:

    idorderid1orderid2orderid3

    5001dev.netQA.comTest.net

    Can some one out there help me writing this query.

  • Something like this?

    select

    id

    ,max(case when orderid = 1 then dns else null end) as 'orderid1'

    ,max(case when orderid = 2 then dns else null end) as 'orderid2'

    ,max(case when orderid = 3 then dns else null end) as 'orderid3'

    from

    #DNS

    group by

    id;

    - Jeff

    - Jeff

  • Thanks Jeff. That's what I needed.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply