Results 1 to 3 of 3
  1. #1
    Join Date
    May 2007
    Posts
    3

    Unanswered: Coverting columns to a row?

    I have the following table below:

    Q1 Q2_1 Q2_2 Q2_3 Q2_4 starttime endtime
    2 1 (null) 3 4 17-May-05 17-May-05
    2 1 2 (null) 4 18-May-05 18-May-05
    1 1 (null) 3 (null) 18-May-05 18-May-05
    2 (null) 2 3 (null) 18-May-05 18-May-05
    2 (null) (null) 3 4 18-May-05 18-May-05
    1 1 (null) (null) (null) 18-May-05 18-May-05
    1 1 (null) (null) 4 19-May-05 19-May-05


    Now, I want Q2 to be all in one column based on the previous columns above. Can anyone help me convert from columns to a single row?

    Q1 Q2 starttime endtime
    2 1 17-May-05 17-May-05
    2 1 18-May-05 18-May-05
    1 1 18-May-05 18-May-05
    2 (null) 18-May-05 18-May-05
    2 (null) 18-May-05 18-May-05
    1 1 18-May-05 18-May-05
    1 1 19-May-05 19-May-05
    2 (null) 17-May-05 17-May-05
    2 2 18-May-05 18-May-05
    1 (null) 18-May-05 18-May-05
    2 2 18-May-05 18-May-05
    1 (null) 18-May-05 18-May-05
    1 (null) 19-May-05 19-May-05
    2 3 17-May-05 17-May-05
    2 (null) 18-May-05 18-May-05
    1 3 18-May-05 18-May-05
    2 3 18-May-05 18-May-05
    2 3 18-May-05 18-May-05
    1 (null) 18-May-05 18-May-05
    1 (null) 19-May-05 19-May-05
    2 4 18-May-05 18-May-05
    2 4 18-May-05 18-May-05
    1 (null) 18-May-05 18-May-05
    2 (null) 18-May-05 18-May-05
    2 4 18-May-05 18-May-05
    1 (null) 18-May-05 18-May-05
    1 4 19-May-05 19-May-05

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    search this forum for "pivot query"
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Nov 2002
    Posts
    272
    Wouldn't a pivot do the opposite?

    If I get it correctly we want a union of 4 selects:

    Select Q1, Q2_1, StartTime, EndTime From...
    UNION
    Select Q1, Q2_2, StartTime, EndTime From...
    UNION
    Select Q1, Q2_3, StartTime, EndTime From...
    UNION
    Select Q1, Q2_4, StartTime, EndTime From...

Posting Permissions

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