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

Insertion and Deletion of rows


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

Active User


Joined: 05 Jun 2005
Posts: 165
Location: Bangalore

PostPosted: Wed Jan 23, 2008 4:22 pm
Reply with quote

hi,
can anyone help me in my requirement?

i have a table with a column in which integers are stored in ascending order. whenever a new row is inserted into the table, it reads the maximum value available in the table and adds 1 to it to insert the new row. i need to delete the row with the smallest value in that column with every insertion. its like the GDG versions, when the new one is created the oldest one gets deleted.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Wed Jan 23, 2008 4:27 pm
Reply with quote

Just like you select the max value, you can select the min value. Then just delete it....
Back to top
View user's profile Send private message
the_gautam

Active User


Joined: 05 Jun 2005
Posts: 165
Location: Bangalore

PostPosted: Wed Jan 23, 2008 11:07 pm
Reply with quote

i ve tried it. i can do it in cobol-db2 batch program. however, not getting it done in spufi.
Back to top
View user's profile Send private message
mkk157

Active User


Joined: 17 May 2006
Posts: 310

PostPosted: Thu Jan 24, 2008 11:19 am
Reply with quote

Gautam,

U can achieve this through:

1) SPUFI:

U can run the 2 queries one time.
Before inserting a new row into the table u can run another query to delete the row with the least integer value as you said.

2) TRIGGER:

U can write a trigger to delete the row with the least integer value, when ever user tries to enter a new row into the table.


Correct me If I am wrong...
Back to top
View user's profile Send private message
the_gautam

Active User


Joined: 05 Jun 2005
Posts: 165
Location: Bangalore

PostPosted: Thu Jan 24, 2008 3:09 pm
Reply with quote

thanks for the suggestion. can someone please give me the query?
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Thu Jan 24, 2008 6:42 pm
Reply with quote

DELETE FROM table WHERE intcolumn = min(intcolumn);
INSERT ....
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Thu Jan 24, 2008 6:50 pm
Reply with quote

Since you can do it in COBOL, you must know how to write the SQL.

Since you are still asking, however, perhaps we can send someone over to type it in for you?
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 To get the count of rows for every 1 ... DB2 3
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Convert single row multi cols to sing... DFSORT/ICETOOL 6
No new posts Compare latest 2 rows of a table usin... DB2 1
No new posts How to compare two rows of same table DB2 11
Search our Forums:

Back to Top