Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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 How to insert a value on specific pos... Poha Eater DFSORT/ICETOOL 9 Sun Oct 01, 2017 3:04 am
No new posts Conditional highlighting of rows in I... packerm CLIST & REXX 2 Thu Sep 21, 2017 6:50 pm
No new posts Insert a Row_number into table useit DB2 2 Tue Sep 19, 2017 1:07 pm
No new posts column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm
No new posts Convert rows and column into JSON for... Dinesh Manivannan DB2 2 Sun Sep 03, 2017 6:50 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us