Hi,
is it possible to delete top 1000 (FirstOnly1000?) records from table? If yes, what is best code to use?
While select firstOnly1000? or I can somehow use delete_from too?
Thanks.
*This post is locked for comments
The easiest (but slowest) option would be to do it in a loop, delete one record at a time and increase a counter every time. When the counter reaches 1000 or if there are no more records left, you break out of the loop.
In AX2012, up to and including R3, you may get a performance improvement depending on your table and whether the delete() method has been overridden, if you first determine the RecIds you want to delete, stuff them into a temporary table (TempDB type) and then do a delete_from on your table, joined to that temporary table.
RecId blocks are almost sequential, you may try that, but it is not guaranteed it will be exactly 1000 records at all. Fetch first record by your ordering criteria, get RecId, add 1000, then call the set-based delete operation on it where RecId >= yourstoredRecId and <= yourstoredRecId+1000.
Since RecId is an index most of the times as well in a table, doing a range for it with a delete recordset block could be fast as well.
Hi JOni,
Delete_from is not working here as you can only add some ranges. I wonder what would be the background of your question. For now, I would say a while select would help you, but might be slow...
If it is possible with SQL, you could consider using the Sstatement / Connection classes to execute a SQL statement directly from AX.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 2 Most Valuable Professional
Guy Terry 2 Moderator
Rahul Shah 2