Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2003
    Posts
    223

    Unanswered: How to put select output into different columns?

    I have a table like:

    ID Disc
    ----------------
    1 BUSH
    2 JOHN
    1 GOLE
    2 MIKE

    I would like output depending on ID to put Disc into two columns. Like:

    ID Disc1 Disc2
    ----------------------------
    1 BUSH NULL
    2 NULL JOHN
    1 GOLE NULL
    2 NULL MIKE

    Any help will be appreciated. Thanks

    ZYT

  2. #2
    Join Date
    Feb 2004
    Posts
    492
    If the ID is limited (not too much) then this might work for you:

    select id
    , case id when 1 then Disc else null end [Disc1]
    , case id when 2 then Disc else null end [Disc2]
    ...

  3. #3
    Join Date
    Aug 2004
    Posts
    54
    you could create a select statement something like this:

    Code:
    select id,
    	case
    		when id=2 then null
    		when id=1 then Disc
    	End as Disc1,
    	case
    		when id=2 then Disc
    		when id=1 then null
    	End as Disc2
    from <table>
    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •