SQL ステートメントを FoxPro に変換できません。私が抱えている問題は、「 関数名がありません )」というエラーコードが表示されることですが、何がどこに問題があるのか わかりません。問題は下の行にあります。どんな助けでも大歓迎です。
NVL(select sum(amount) from tpaymentitem where tpaymentitem.invoiceid = 0 and tpaymentitem.programid = (select max(tinvoiceitem.programid) FROM tinvoiceitem),0) as prepay,;
foxpro コード全体を以下に示します。
Select acc.accountid,;
ti.invoiceid,;
ti.invoicedate,;
DATE() - ti.invoicedate as invage,;
sum(NVL([subtotalregular],0) + NVL([fedtaxregular],0) + NVL([statetaxregular],0) + NVL([localtaxregular],0)) as invamount, ;
NVL((select sum(amount) from tpaymentitem where invoiceid = ti.invoiceid),0) as paidamt,;
(sum(NVL([subtotalregular],0) + NVL([fedtaxregular],0) + NVL([statetaxregular],0) + NVL([localtaxregular],0)) - NVL((select sum(amount) from tpaymentitem where invoiceid = ti.invoiceid),0)) as invbalance,;
max(tii.programid) as programid,;
NVL(select sum(amount) from tpaymentitem where tpaymentitem.invoiceid = 0 and tpaymentitem.programid = (select max(tinvoiceitem.programid) FROM tinvoiceitem),0) as prepay,;
do while com.stchargeinterest = 1 AND acc.nofincharge = 0 ;
if DATE() - ti.invoicedate >= com.stmindaysforinterest ;
ROUND((sum(NVL([subtotalregular],0) + NVL([fedtaxregular],0) + NVL([statetaxregular],0) + NVL([localtaxregular],0)) - NVL((select sum(amount) from tpaymentitem where invoiceid = ti.invoiceid),0)) * ((com.stinterestrate / 365) * DATE() - ti.invoicedate)),2);
ENDif ;
ENDdo as financecharge,;
com.stchargeinterest,;
com.stinterestrate,;
acc.nofincharge,;
com.stmindaysforinterest,;
com.stinterval;
INTO cursor tmpbalance;
FROM taccount acc;
INNER JOIN tcompany com ON com.companyid=acc.companyid;
LEFT JOIN tinvoice ti ON ti.accountid=acc.accountid;
LEFT JOIN tinvoiceitem tii ON ti.invoiceid=tii.invoiceid;
WHERE acc.accountid = m.cust_no AND acc.companyid = 1;
GROUP BY acc.accountid,ti.invoiceid,ti.invoicedate,com.stinterval,com.stchargeinterest ,;
com.stinterestrate,acc.nofincharge,com.stmindaysforinterest,acc.companyid
変換元の SQL コードは以下のとおりで、もともとはストアド プロシージャからキャプチャされたものです。
Select acc.accountid,ti.invoiceid,ti.invoicedate,DateDiff(d,ti.invoicedate,getdate()) as invage,
sum(isnull([subtotalregular],0)+isnull([fedtaxregular],0)+isnull([statetaxregular],0)
+isnull([localtaxregular],0)) as invamount,
ISNULL((select sum(amount) from tpaymentitem where invoiceid=ti.invoiceid),0) as paidamt,
(sum(isnull([subtotalregular],0)+isnull([fedtaxregular],0)+isnull([statetaxregular],0)
+isnull([localtaxregular],0)) -
ISNULL((select sum(amount) from tpaymentitem where invoiceid=ti.invoiceid),0)) as invbalance,
max(tii.programid) as programid,
ISNULL((select sum(amount) from tpaymentitem where invoiceid=0 and programid = max(tii.programid)),0) as prepay,
CASE WHEN (com.stchargeinterest = 1) AND (acc.nofincharge=0) THEN
CASE WHEN DateDiff(d,ti.invoicedate,getdate()) >= com.stmindaysforinterest THEN
ROUND((sum(isnull([subtotalregular],0)+isnull([fedtaxregular],0)+isnull([statetaxregular],0)+isnull([localtaxregular],0))
-ISNULL((select sum(amount) from tpaymentitem where invoiceid=ti.invoiceid),0))
* ((com.stinterestrate / 365) * DateDiff(d,ti.invoicedate,getdate())),2)
ELSE 0 END
ELSE 0 END as financecharge,com.stchargeinterest ,com.stinterestrate,
acc.nofincharge,com.stmindaysforinterest,com.stinterval
INTO #tmpbalance
FROM taccount acc
INNER JOIN tcompany com ON com.companyid=acc.companyid
LEFT JOIN tinvoice ti ON ti.accountid=acc.accountid
LEFT JOIN tinvoiceitem tii ON ti.invoiceid=tii.invoiceid
WHERE acc.accountid= @accountid AND acc.companyid = @companyid
GROUP BY acc.accountid,ti.invoiceid,ti.invoicedate,com.stinterval,com.stchargeinterest ,
com.stinterestrate,acc.nofincharge,com.stmindaysforinterest,acc.companyid