Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2004
    Posts
    2

    Angry Unanswered: Convert Existing Table to a new Table with a new layout

    I am trying to write an SQL query that takes one table and its data, rearrages it into a new fomat and creates a new table with the newly rearranged data. Below is the example of what I currently have and what I want to make it look like. Please ignore the extra " ---- ", I did this to try and keep the spacing so it would be easier to read.

    Original Table Layout

    Column1 - Column2 - Column3 - Column4
    Item# ---- CNAME1 -- CNAME2 - CNAME3
    ---------- - ---------- - ---------- - -----------
    1234 ----- S ---------- NS -------- NS
    6789 ----- NS -------- S ---------- NS


    New Table Layout

    Column1 - Column2 - Column3
    Item# ---- RDC ------ S/NS
    ------- ---- ---------- -- -----------
    1234 ----- CNAME1 -- S
    1234 ----- CNAME2 -- NS
    1234 ----- CNAME3 -- NS
    6789 ----- CNAME1 -- NS
    6789 ----- CNAME2 -- S
    6789 ----- CNAME3 -- NS


    It's been a while for me writing SQL statements and I am a little rusty. I have done this in the past but I just can't figure it out now, so if anyone has an answer for me I would greatly appriciate it.

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Convert Existing Table to a new Table with a new layout

    select column1, 'CNAME1', column2
    from ...
    union all
    select column1, 'CNAME2', column3
    from ...
    union all
    select column1, 'CNAME3', column4
    from ...

  3. #3
    Join Date
    Mar 2004
    Posts
    2

    Cool

    Thanks for the help!!!

Posting Permissions

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