IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Insert rows from table1 to table2


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Shobana Bhaskar

New User


Joined: 02 Mar 2007
Posts: 35
Location: Pennsylvania, US

PostPosted: Tue Apr 10, 2007 11:10 am
Reply with quote

Hi all,

I need to insert values from table1 into table2 as below.

Table1:
Col1 Col2
ValA 1000
ValB 2000
ValC 3000

Table2:
ValA ValB ValC
1000 2000 3000

Here Col1 and Col2 are the columns of table1 and ValA, ValB, ValC are columns of table2.
ie.The Column names of table2 are values in Col1 of Table1. I need to insert data in the way i have shown above. Please help me!!

Thanks
Back to top
View user's profile Send private message
Jash_br

New User


Joined: 30 Mar 2007
Posts: 5
Location: Chennai

PostPosted: Tue Apr 10, 2007 11:14 am
Reply with quote

Hi Shobana,
U mean pivoting ? Hope you can use case statements as for each column.

Insert into table2
select
case col1 = valA then 1000 end
,case col1 = valB then 2000 end
,case col1 = valC then 3000 end

from table1

Try if this helps icon_biggrin.gif
Back to top
View user's profile Send private message
ragganga

New User


Joined: 22 Jan 2007
Posts: 18
Location: bangalore

PostPosted: Tue Apr 10, 2007 1:57 pm
Reply with quote

Hi Shobana,

Select a record from Table1 using Cursor method then insert into Table2 using Insert command.

Synatx for Cursor and Insert you can find it in forum or any web site
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Insert header record with record coun... DFSORT/ICETOOL 14
No new posts Insert system time/date (timestamp) u... DFSORT/ICETOOL 5
No new posts Identify Program Insert DB2 7
Search our Forums:

Back to Top