Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Insert rows from table1 to table2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Insert rows from table1 to table2
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    Post subject: Re: Insert rows from table1 to table2
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts To display values of multiple rows in... vinu78 DB2 2 Thu Mar 09, 2017 1:20 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
This topic is locked: you cannot edit posts or make replies. DB2 query Using Recursion, Converting... smilewithashu2 DB2 3 Tue Jan 03, 2017 12:50 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
No new posts Row-Numbers of distinct rows? Auryn DB2 1 Thu Oct 20, 2016 4:38 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us