Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

automatic insertion of a new value in a column

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: automatic insertion of a new value in a column
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    Post subject:
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    Post subject: Reply to: automatic insertion of a new value in a column
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    Post subject: Reply to: automatic insertion of a new value in a column
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Add system date inside of a PS file a... pramitdas DFSORT/ICETOOL 5 Sun Aug 28, 2016 12:06 am
No new posts Converting NULL column into NOT NULL ... Raghu navaikulam DB2 5 Sat Aug 06, 2016 3:45 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us