Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2004
    Posts
    6

    Unanswered: single select of a multi occuring data formatting specificity

    I'm working on a simple db call, but am wondering if there is an easy way to format it in a specific way.

    heres what i do
    -------------------------------------------
    select ' ' col1, col2, col3 orderby_col3, col3
    from table
    union
    select col1, ' ' col2, col3 orderby_col3, ' ' col3
    from table
    where col1='something' and col2='something'
    union
    select col1, ' ' col2, col3 orderby_col3, ' ' col3
    from table
    where col1='somethingelse' and col2='somethingelse'
    order by orderby_col3
    -----------------------------------------------
    thats the basic idea, and the ouput is something like the following, ordering by the column whos data is only shown once for each set

    col1
    col2 col3
    col2 col3
    col2 col3
    col1
    col2 col3
    col2 col3
    col1
    col2 col3
    col2 col3
    col2 col3
    col2 col3

    this is close to what i need, but not quite it, is there a way to get the col1 to sync up with the rest such that it looks like

    col1 col2 col3
    col2 col3
    col2 col3
    col1 col2 col3
    col2 col3
    col1 col2 col3
    col2 col3
    col2 col3
    col2 col3

    i can't seem to find a way to do this without the col1 reapeating down the left side. anyone have a solution? i guess shifting data col2 and col3 up?

    thanks, Brian

  2. #2
    Join Date
    Aug 2004
    Posts
    330
    Sounds like a CASE statement.

Posting Permissions

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