Dear All I write some syntax for sql

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?