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 with Select

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Insert with Select
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: 1013
Location: India

PostPosted: Sat Nov 14, 2009 5:09 pm    Post subject:
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

Site Director


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

PostPosted: Sat Nov 14, 2009 10:06 pm    Post subject:
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    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 SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 am
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm
No new posts Insert Lines in JCL with Rexx after a... Willy Jensen CLIST & REXX 3 Tue Aug 30, 2016 4:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Select first 2 group data vice_versa DFSORT/ICETOOL 10 Mon Jun 13, 2016 2:21 pm


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