web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Delete record form table

(0) ShareShare
ReportReport
Posted on by 570

HI All,

I have customize table  in that ten sample record is there all are string field ,I use below code to delete the record ,but is not working,Please help on this  

public static void main(Args _args)

{

JMTrialTestTB JMTrialTestTB;

delete_from JMTrialTestTB

where str2Int(JMTrialTestTB.BU) >= 6 && str2Int(JMTrialTestTB.BU) <= 8 ;

}

04873.Capture.PNG

 

I have the same question (0)
  • Suggested answer
    MCallebert Profile Picture
    45 on at

    Hi Tony,

    Try to encapsulate your query in a transaction

  • TonyAx Profile Picture
    570 on at

    Hi MCallebert.

    Thanks for the reply, Could you please provide more details on this .

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Your problem is that you have x function str2int in this statement.

    If you would see the resulting SQL statement, you would notice that at the time when str2int is called, you don't have anything selected in JMTrialTestB buffer, hence the result is 0.

    Remember that the system first has to generate the SQL statement, then send this SQL statement to the database. And this database that you send to the database will obviously not contain any x logic.

    So your statement is actually:

    delete_from JMTrialTestTB where 0 >= 6 && 0 <= 8;

    But you could just do it like this:

    delete_from JMTrialTestTB 
        where JMTrialTestTB == '6' 
        || JMTrialTestTB == '7' 
        || JMTrialTestTB == '8';

    If this is not feasible (you have to handle dozens of numbers), then you have to use a while select statement, and evaluate your condition one record at a time.

    UPDATE: fixed typos.

  • TonyAx Profile Picture
    570 on at

    Hi,

    Thanks for reply, I want to delete the record between  6 to 9 record .

    Its possible to use delete_from method

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    Hi Tony,

    yes, it's possible.

  • TonyAx Profile Picture
    570 on at

    I Tried below code ,but no luck,could you please share your org code

    delete_from JMTrialTestTB

    where  0 >= 6 && 0  <= 8 ;

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    Did you try the code that I already shared? I don't have any other suggestions, just this one.

  • Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at

    You could use comparison operators with string fields as well:

    delete_from jmTrialTestTB
    	where jmTrialTestTB.BU >= '6' && jmTrialTestTB.BU <= '8';

    But you would quickly get into troubles because 9 > 10 isn't the same as '9' > '10'.

    If you want to have numbers in those fields and work with them as with number, they should be numbers. You have a wrong data type there. And if you want to allow strings there, then it's wrong to expect just numbers.

    If you really can't do either, you can create a view with a computed column where you'll try to convert strings to numbers. Then you can filter by this computed column.

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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans