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

Insert with Select


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

New User


Joined: 07 Sep 2007
Posts: 6
Location: chennai

PostPosted: Fri Nov 13, 2009 9:14 pm
Reply with quote

Hi,

Here is the scenario:
I have a table with 3 columns with primary field as F1
i want to create another set of these rows but with a primary key as B instead of A in column F1,cloning all other columns as with F1= A

Original table : F1=primary key
F1 F2 F3
A D I
A E J
A F K
A G L
A H M
'''''''''''''
'''''''
''
'

Expected table after INSERT

F1 F2 F3
A D I
A E J
A F K
A G L
A H M

B D I
B E J
B F K
B G L
B H M
'''''''''''''
'''''''
''
'
Hope u guys understand what i implied.
Please assist.
Back to top
View user's profile Send private message
sushanth bobby

Senior Member


Joined: 29 Jul 2008
Posts: 1020
Location: India

PostPosted: Sat Nov 14, 2009 5:09 pm
Reply with quote

shashikant,

What you looking for is
Code:
insert into table
select 'B',f2,f3 from table


Not tested.


Sushanth
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Nov 14, 2009 10:06 pm
Reply with quote

Hello,

If you want only rows with F1 = A replicated as Bs, add this to the SELECT:
Code:
   WHERE F1 = 'A'

Without this, all rows in the table will be copied with B as the value for F1.
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 Dynamically pass table name to a sele... DB2 2
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
No new posts SELECT from data change table DB2 5
Search our Forums:

Back to Top