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

Get max in insert is not working because of the subquey


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

New User


Joined: 20 Feb 2006
Posts: 34

PostPosted: Wed Feb 07, 2007 6:16 pm
Reply with quote

Hi,

I have a table T1 with following fields
SEQ NUM,
NAME

SEQ NUM is primary key of the table.

I have some records in T1 with name M1.

I want to write
insert into T1
(SEQ NUM,
NAME)
SELECT
(select max(SEQ NUM)+1 from T1),
M2)

This query is not working because of the subquery which i have used to increase the SEQ NUM.
Could any one suggest how to do this insert?
any ideas plz

Regards
Rashmi
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Feb 07, 2007 9:52 pm
Reply with quote

Your looking to insert a single record with this SQL execution? (Not multiple records incrementing seq_num)?
Back to top
View user's profile Send private message
rashmi.ranjan75

New User


Joined: 20 Feb 2006
Posts: 34

PostPosted: Wed Feb 07, 2007 10:33 pm
Reply with quote

there are mulitple records
Back to top
View user's profile Send private message
wanderer

Active User


Joined: 05 Feb 2007
Posts: 199
Location: Sri Lanka

PostPosted: Thu Feb 08, 2007 6:20 am
Reply with quote

rashmi.ranjan75 wrote:
SELECT
(select max(SEQ NUM)+1 from T1),
M2)



So what is the error you are getting? It would be helpful to paste it here.

To me it seems that there is no FROM clause in your select. May be you can add one "from sysibm.sysdummy1".
Back to top
View user's profile Send private message
rashmi.ranjan75

New User


Joined: 20 Feb 2006
Posts: 34

PostPosted: Thu Feb 08, 2007 1:53 pm
Reply with quote

sql error code coming is -4700 and sqlstate is 56038

the actual query is

insert into T1
(SEQ NUM,
NAME)
SELECT
(select max(SEQ NUM)+1 from T1),
M2)
from
T1;

Thanks to see if it is possible somehow
Back to top
View user's profile Send private message
vini_srcna

Active User


Joined: 26 May 2005
Posts: 178
Location: Copenhagen, Denmark

PostPosted: Thu Feb 08, 2007 6:42 pm
Reply with quote

Try this query,This should work

insert into T1 (SEQ NUM, NAME)
SELECT max(SEQ NUM)+1,'M2' from T1 ;
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 PD not working for unsigned packed JO... DFSORT/ICETOOL 5
No new posts Def PD not working for unsigned packe... JCL & VSAM 3
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
Search our Forums:

Back to Top