Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Can some one guide me for sql to x++

(0) ShareShare
ReportReport
Posted on by 253

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?

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

    Thanks Girish.

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

    Thanks Mohit

  • Verified answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 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.

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 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;

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

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans