| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

09-09-09, 01:09
|
|
Registered User
|
|
Join Date: Mar 2009
Posts: 73
|
|
|
Selecting sequence inside row copy query.
|
|
Hello folks,
I have a scenario where I have to duplicate insert a record inside the same table. I am having problem in generating the serial for the insert query as the id field in the table is a sequence field.
Here is my query
Code:
INSERT INTO ADMINISTRATOR.UWPROPTRTY (GENTREATYSRNO, GENTREATYYEAR, GENTREATYCODE, GENSUBBUSICLASS, GENCLIENTCODE, GENCURRCODE, GENENTRYDATE, GENTREATYDATEFROM, GENTREATYDATETO, GENDESCRIPTION, GENPTRTYSTATUS, DATETIME, LASTMODIFYBY, TERMINALID, GENRENEWSTAT, PREVTRTSRNO)
values (select (SELECT NEXTVAL FOR administrator.ptrt_seq as seqid FROM sysibm.sysdummy1), GENTREATYYEAR, GENTREATYCODE, GENSUBBUSICLASS, GENCLIENTCODE, GENCURRCODE, GENENTRYDATE, GENTREATYDATEFROM, GENTREATYDATETO, GENDESCRIPTION, GENPTRTYSTATUS, DATETIME, LASTMODIFYBY, TERMINALID, GENRENEWSTAT, PREVTRTSRNO from administrator.uwproptrty where gentreatysrno=261 )
Help me guys
Best regards, Mike.
|
|

09-09-09, 01:19
|
|
Registered User
|
|
Join Date: Feb 2008
Location: Japan
Posts: 2,193
|
|
|
|

09-09-09, 01:19
|
|
Registered User
|
|
Join Date: May 2003
Location: USA
Posts: 5,196
|
|
|
|
I am not sure I understand what you are trying to do, but if want to find out what value was used in an insert with a NEXTVAL FOR sequence-name, then you should look at the FINAL TABLE syntax.
Select GENTREATYSRNO from FINAL TABLE (
INSERT INTO ADMINISTRATOR.UWPROPTRTY
(GENTREATYSRNO, GENTREATYYEAR, GENTREATYCODE, GENSUBBUSICLASS, GENCLIENTCODE, GENCURRCODE, GENENTRYDATE, GENTREATYDATEFROM, GENTREATYDATETO, GENDESCRIPTION, GENPTRTYSTATUS, DATETIME, LASTMODIFYBY, TERMINALID, GENRENEWSTAT, PREVTRTSRNO)
values (NEXTVAL FOR administrator.ptrt_seq, GENTREATYYEAR, GENTREATYCODE, GENSUBBUSICLASS, GENCLIENTCODE, GENCURRCODE, GENENTRYDATE, GENTREATYDATEFROM, GENTREATYDATETO, GENDESCRIPTION, GENPTRTYSTATUS, DATETIME, LASTMODIFYBY, TERMINALID, GENRENEWSTAT, PREVTRTSRNO)
);
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
|
|

09-09-09, 01:26
|
|
Registered User
|
|
Join Date: Mar 2009
Posts: 73
|
|
I cannot select the next sequence as the primary key for the row I am inserting inside my select statement. Because select next val for seq)as id is not working with multiple select.
Quote:
|
Originally Posted by tonkuma
What is your problem?
|
|
|

09-09-09, 01:28
|
|
Registered User
|
|
Join Date: Mar 2009
Posts: 73
|
|
Thanks for the reply Marcus. I am trying to insert a row again in the same table with a new serial. I have limitation in my table that the primary key is a sequence field so that's why I am trying to select nextval from the sequence so I could fetch the primary key to insert for the new row.
Quote:
|
Originally Posted by Marcus_A
I am not sure I understand what you are trying to do, but if want to find out what value was used in an insert with a NEXTVAL FOR sequence-name, then you should look at the FINAL TABLE syntax.
Select GENTREATYSRNO from FINAL TABLE (
INSERT INTO ADMINISTRATOR.UWPROPTRTY
(GENTREATYSRNO, GENTREATYYEAR, GENTREATYCODE, GENSUBBUSICLASS, GENCLIENTCODE, GENCURRCODE, GENENTRYDATE, GENTREATYDATEFROM, GENTREATYDATETO, GENDESCRIPTION, GENPTRTYSTATUS, DATETIME, LASTMODIFYBY, TERMINALID, GENRENEWSTAT, PREVTRTSRNO)
values (NEXTVAL FOR administrator.ptrt_seq, GENTREATYYEAR, GENTREATYCODE, GENSUBBUSICLASS, GENCLIENTCODE, GENCURRCODE, GENENTRYDATE, GENTREATYDATEFROM, GENTREATYDATETO, GENDESCRIPTION, GENPTRTYSTATUS, DATETIME, LASTMODIFYBY, TERMINALID, GENRENEWSTAT, PREVTRTSRNO)
);
|
|
|

09-09-09, 07:46
|
|
:-)
|
|
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
|
|
The syntax of your INSERT is incorrect. Check the manual.
|
|

09-09-09, 23:08
|
|
Registered User
|
|
Join Date: Mar 2009
Posts: 73
|
|
|
Hi..
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|