If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Select Query Question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-31-04, 16:33
atmosphere atmosphere is offline
Registered User
 
Join Date: Aug 2004
Posts: 19
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
Reply With Quote
  #2 (permalink)  
Old 08-31-04, 17:15
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On