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

automatic insertion of a new value in a column


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ANISH THOMAS

New User


Joined: 23 Jan 2008
Posts: 2
Location: pune

PostPosted: Thu Feb 14, 2008 4:18 pm
Reply with quote

hi! all,

i want to insert a value in a column depending on the previous value of that same column.

let me clear it with a example.

i have a employee table( columns are emp-id, name, salary). now i want to add a new row to that table. so i want that the emp-id column to be inserted automatically with different values whenever i insert a new row.
so how will i write a querry which will fetch the last emp-id n based on that it will generate a new emp-id(like incrementing the last emp-id value).

i hope i am clear.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Feb 14, 2008 4:31 pm
Reply with quote

Code:
SELECT MAX(emp_id)+1 FROM emp_table;
Back to top
View user's profile Send private message
ravi17s
Warnings : 1

New User


Joined: 15 Aug 2003
Posts: 57

PostPosted: Fri Feb 15, 2008 2:42 pm
Reply with quote

If your are in V8 I suggest you to go for Identity column.
More easy to maintain.....

In your ex the EMP_ID column must be defined as an Identity column.
Back to top
View user's profile Send private message
abhishekmdwivedi

New User


Joined: 22 Aug 2006
Posts: 95
Location: india

PostPosted: Fri Feb 15, 2008 3:27 pm
Reply with quote

Hi ,

This might be helpful,
Create table emp1(
emp_no integer not null
generated always as identity
(start with 1
,increment by 1
, no maxvalue
,no cycle
,order)
,name .....
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 Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts first column truncated in search result IBM Tools 13
No new posts Split a record with data in a differe... DFSORT/ICETOOL 8
Search our Forums:

Back to Top