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 564

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

 

  • Martin Dráb Profile Picture
    231,923 Most Valuable Professional on at
    RE: Delete record form table

    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.

  • nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Delete record form table

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

  • TonyAx Profile Picture
    564 on at
    RE: Delete record form table

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

    delete_from JMTrialTestTB

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

  • Suggested answer
    nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Delete record form table

    Hi Tony,

    yes, it's possible.

  • TonyAx Profile Picture
    564 on at
    RE: Delete record form table

    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,156 Moderator on at
    RE: Delete record form table

    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
    564 on at
    RE: Delete record form table

    Hi MCallebert.

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

  • Suggested answer
    MCallebert Profile Picture
    45 on at
    RE: Delete record form table

    Hi Tony,

    Try to encapsulate your query in a transaction

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,207 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,923 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans