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 > INSERT INTO between two tables!!!! please help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-31-05, 13:01
M_RAS M_RAS is offline
Registered User
 
Join Date: Sep 2003
Location: canada
Posts: 230
INSERT INTO between two tables!!!! please help

I am working with db2 v8.2 and aix 5.2,

I have two tables like this:
tab1(id,t1d,t1n,t1m,t2d,t2n,t2m,t3d,t3n,t3m) id is PK
tab2(id,d,n,m) id is PK and table is empty

I need insert from tab1 into tab2 such that t1d,t2d,t3d insert into d
and t1n,t2n,t3n into n and t1m,t2m,t3m into m.

Thank you inadvance for your help.
Reply With Quote
  #2 (permalink)  
Old 10-31-05, 14:26
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Can you give a few example rows? I'm not entirely sure what you're trying to do.

Specifically:
" t1d,t2d,t3d insert into d" -> how do 3 columns become 1 in the new table?
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #3 (permalink)  
Old 10-31-05, 14:35
M_RAS M_RAS is offline
Registered User
 
Join Date: Sep 2003
Location: canada
Posts: 230
Quote:
Originally Posted by J Petruk
Can you give a few example rows? I'm not entirely sure what you're trying to do.

Specifically:
" t1d,t2d,t3d insert into d" -> how do 3 columns become 1 in the new table?
Hi J Petruk,
I did not mean we insert three values to one column in one row, but it is possible in three rows.
Reply With Quote
  #4 (permalink)  
Old 10-31-05, 14:41
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Do just you mean this, then?

INSERT INTO TAB2 SELECT ID, T1D, T1N, T1M FROM TAB1;
INSERT INTO TAB2 SELECT ID, T2D, T2N, T2M FROM TAB1;
INSERT INTO TAB2 SELECT ID, T3D, T3N, T3M FROM TAB1;
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #5 (permalink)  
Old 10-31-05, 14:49
M_RAS M_RAS is offline
Registered User
 
Join Date: Sep 2003
Location: canada
Posts: 230
Quote:
Originally Posted by J Petruk
Do just you mean this, then?

INSERT INTO TAB2 SELECT ID, T1D, T1N, T1M FROM TAB1;
INSERT INTO TAB2 SELECT ID, T2D, T2N, T2M FROM TAB1;
INSERT INTO TAB2 SELECT ID, T3D, T3N, T3M FROM TAB1;
It backed to me error

DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0412N Multiple columns are returned from a subquery that is allowed only
one column. SQLSTATE=42823
Reply With Quote
  #6 (permalink)  
Old 10-31-05, 15:12
J Petruk J Petruk is offline
Registered User
 
Join Date: Mar 2004
Location: Toronto, ON, Canada
Posts: 513
Hurumph, should work. Post your sql and table defs.
__________________
--
Jonathan Petruk
DB2 Database Consultant
Reply With Quote
  #7 (permalink)  
Old 11-01-05, 11:11
M_RAS M_RAS is offline
Registered User
 
Join Date: Sep 2003
Location: canada
Posts: 230
Quote:
Originally Posted by J Petruk
Hurumph, should work. Post your sql and table defs.
I was wrong and your suggestion worked very well .

Thank you again fro your help.
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