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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Can some one guide me for sql to x++

(0) ShareShare
ReportReport
Posted on by 276

Dear All I write some syntax for sql

pastedimage1678762855694v1.png

After that I go to a code and convert to x++;

==================================================

My code:

display String20 ppvno()
{
HSTHPaymAdviceTable PaymAdviceTable;
HSTHPaymAdviceLine paymAdviceLine;
VendTrans VendTrans;
str ppvVoucher = "";
;

while select PaymAdviceTable
join paymAdviceLine
where paymAdviceLine.PAYMADVICEID == PaymAdviceTable.PAYMADVICEID
join VendTrans
where VendTrans.LASTSETTLEVOUCHER == paymAdviceLine.DOCUMENT
&& VendTrans.VOUCHER like '%PPV%' // when I put this code output will show blank but if not it's sound work by logical but not match my requirement
&& PaymAdviceTable.PAYMADVICEID == 'PAV0026123' //this.PaymAdviceId //
{
ppvVoucher = VendTrans.VOUCHER;
break; // Only need the first PPV voucher, so exit the loop after the first result
}

return ppvVoucher;

}

==================================================

Can some one guide me how to solve?

I have the same question (0)
  • Suggested answer
    Mohit Rampal Profile Picture
    12,563 Moderator on at
    RE: Can some one guide me for sql to x++

    Hi, If you want only first record then while select loop is not required. I haven't tested the code but tried to re-factor your code, please check and see if it works

    select firstonly Voucher from VendTrans
        join paymAdviceLine
    where paymAdviceLine.DOCUMENT == VendTrans.LASTSETTLEVOUCHER
    && VendTrans.VOUCHER like '%PPV%'
        join PaymAdviceTable
    where PaymAdviceTable.PAYMADVICEID == paymAdviceLine.PAYMADVICEID 
    && PaymAdviceTable.PAYMADVICEID == 'PAV0026123';
    
    return VendTrans.Voucher;

  • Verified answer
    GirishS Profile Picture
    27,825 Moderator on at
    RE: Can some one guide me for sql to x++

    Hi Thanakorn Kanjiropas,

    If it's a display method no need of while select. Single select statement will be enough which will run for all the lines.

    For like operator use like below. 

    display String20 ppvno()
    {
        HSTHPaymAdviceTable PaymAdviceTable;
        HSTHPaymAdviceLine paymAdviceLine;
        VendTrans VendTrans;
        str ppvVoucher = "";
        ;
    
        select PaymAdviceTable
            join paymAdviceLine
            where paymAdviceLine.PAYMADVICEID == PaymAdviceTable.PAYMADVICEID
            join VendTrans
            where VendTrans.LASTSETTLEVOUCHER == paymAdviceLine.DOCUMENT
            && VendTrans.VOUCHER like "*"   PPV  "*" when I put this code output will show blank but if not it's sound work by logical but not match my requirement
            && PaymAdviceTable.PAYMADVICEID == 'PAV0026123' //this.PaymAdviceId //
        {
            ppvVoucher = VendTrans.VOUCHER;
            break; // Only need the first PPV voucher, so exit the loop after the first result
        }
        return ppvVoucher;
    }
    
    

    Thanks,

    Girish S.

  • Chomchanok Profile Picture
    276 on at
    RE: Can some one guide me for sql to x++

    Thanks Mohit

  • Chomchanok Profile Picture
    276 on at
    RE: Can some one guide me for sql to x++

    Thanks Girish.

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 588 Most Valuable Professional

#3
Sumit Singh Profile Picture

Sumit Singh 544

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans