Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Delete record form table

Posted on by 562

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
    Martin Dráb 230,188 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
    nmaenpaa 101,156 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
    TonyAx 562 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
    nmaenpaa 101,156 on at
    RE: Delete record form table

    Hi Tony,

    yes, it's possible.

  • TonyAx Profile Picture
    TonyAx 562 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
    nmaenpaa 101,156 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
    TonyAx 562 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
    MCallebert 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans