File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert a new row with values from an existing record

 
A Kumar
Ranch Hand
Posts: 980
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How can i add a new row with the values of an existing row..the only value that i will supply is the primary key..

I am not getting the sql query for that...

the database i am using is db2..

Is it possible with a single insert statement..What should i do?

Thanks in advance,


[ September 18, 2006: Message edited by: A Kumar ]
[ September 18, 2006: Message edited by: A Kumar ]
 
Scott Selikoff
author
Saloon Keeper
Posts: 3889
15
Eclipse IDE Flex Google Web Toolkit
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe what you are looking for is called an INSERT SELECT statement. Although this can be DB specific the basic syntax is:
 
A Kumar
Ranch Hand
Posts: 980
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks !!!

But what i want is ...

in the insert statement..i will provide the primary key value...and the rest of the columns from another row in the same table..

Regards
 
A Kumar
Ranch Hand
Posts: 980
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a near solution

insert into table
select * from table2 where table2.id=?

But this one wont allow me to specify table.primarykey value explicitly

Regards
 
Shailesh Chandra
Ranch Hand
Posts: 1082
Java Oracle Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by A Kumar:

But this one wont allow me to specify table.primarykey value explicitly



This will certainly allow you to do anything you want, you need to tweak a little bit, assuming TABLE1_ID is your primary key



Shailesh
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic