Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2004
    Posts
    19

    Unanswered: Select Query Question

    Hi

    I have the following database

    Table A:
    ID / Home_Num / Fax_Num / Work_NUM


    And i want the following:

    Table B:
    ID / Phone_Type / Phone_Num
    where Phone_Type is a string representing the type of phone ("Home, Fax, Work")

    If a user has X phone numbers entered in table a, then he should have x rows in table b. ie

    Table A:
    ID / Home_Num / Fax_Num / Work_NUM
    6 / 555-5555 / 333-3333 / NULL

    Then table b should look like

    Table B:
    ID / Phone_Type / Phone_Num
    6 / "Home" / 555-5555
    6 / "Fax" / 333-3333

    Does anyone know how i could accomplish this?
    please help

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Try:

    Insert into tableb (select ID,'Home',home_num from tablea where home_num is not null union select id,'Fax',fax_num from tablea where fax_num is not null union select id,'Work',work_num from tablea where work num is not null)

    Andy

Posting Permissions

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