View previous topic :: View next topic
|
Author |
Message |
itjagadesh
New User
Joined: 05 Dec 2006 Posts: 89 Location: chennai
|
|
|
|
Table A having Ref_nbr as integer,col1,col2...
I need to calculate dynamically the max integer value in insert statement, should accomplish it in interactive mode using BATCH util DSNTEP2
INSERT into table A
Select Max(ref_nbr)+1 from table A,col1,col2,.. hard coded values |
|
Back to top |
|
|
Srihari Gonugunta
Active User
Joined: 14 Sep 2007 Posts: 295 Location: Singapore
|
|
|
|
Jagadesh,
Can you please provide more details.
Just in case, you can try the following.
Code: |
INSERT into tableA
Select Max(ref_nbr)+1,'Hard','Coded','Values'
from tableA; |
|
|
Back to top |
|
|
itjagadesh
New User
Joined: 05 Dec 2006 Posts: 89 Location: chennai
|
|
|
|
A table having primary key as a single integer column,
Table A
Ref_nbr col1 col2 col3
1
2
3
4
5
now I need to insert one row by adding 1 to max(ref_nbr) value.
I tried this query, its working.
INSERT into table A
Sel B.Ref,'Hard','Code' from
(sel max(Ref_nbr) +1 as Ref from table A) B
Thanks for your concern Srihari! |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
The given solution is fine (and has been programmed/implemented in previous versions of DB2) , but if implemented in an operational system this could become a locking bottleneck.
You know DB2 has something like identifiers and/or sequences ?
This lets DB2 handle the automatic incrementing of a column/value. google about and see if this meets your requirement. |
|
Back to top |
|
|
|