我在将 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