| |
|
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.
|
 |

10-31-05, 13:01
|
|
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.
|
|

10-31-05, 14:26
|
|
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
|
|

10-31-05, 14:35
|
|
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.
|
|

10-31-05, 14:41
|
|
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
|
|

10-31-05, 14:49
|
|
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
|
|

10-31-05, 15:12
|
|
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
|
|

11-01-05, 11:11
|
|
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.
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|