Solved

How to delete first N rows in DB2 ?

Posted on 2004-10-11
5
2,103 Views
Last Modified: 2012-06-21
Hi, I am trying to delete first N rows in a DB2 command,
however I can't/don't want to use:
"DELETE FROM TABLE_NAME WHERE COL_NAME IN (SELECT COL_NAME FROM TABLE_NAME FETCH FIRST 'N' ROWS ONLY)"

I have a dynamic build of the delete statement and I have what I have is a constant delete statement that I can add things before it, in the middle of it or after it but I really don't want to change the base delete.

Thanks,
   AmS.
0
Comment
Question by:ams61
  • 2
5 Comments
 
LVL 15

Expert Comment

by:jdlambert1
Comment Utility
You didn't explain why you don't want to use a query with a sub-select, so I'm not sure what you're looking for, but one option is to create a bit field with a default of zero, set it to 1 when you want it deleted, then run a DELETE statement with a WHERE clause that limits the deletion to records where the value is 1.
0
 

Author Comment

by:ams61
Comment Utility
Thanks,
I will explain... I have a constant delete sql statement that I can add parts to its beginning, and\or to its end, I can also add constant statements into the delete statement but it will be very dificult to me to change the original delete statement, especially if I don't know from which table I am going to delete (the delete statement is built dynamicly).
0
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 250 total points
Comment Utility
Is
>I have a constant delete sql statement that I can add parts to
just another way of saying that you build the statement dynamically?

If so, I don't see why you couldn't add
   WHERE COL_NAME IN (SELECT COL_NAME FROM TABLE_NAME FETCH FIRST 'N' ROWS ONLY)
as needed.

Also, if you're building the delete statement dynamically, I don't understand what you mean about not being able to "change the original delete statement".
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
RPG to c# 3 324
Problem to script 14 173
CATALOG A DB2 TCPIP NODE with AN ALIAS 2 116
Data transfer to iSeries failing with message ID SQL0462 6 57
November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now