我正在尝试计算数据库中未结清发票的利率。
我正在使用Microsoft Access数据库,但asp.net/C#不喜欢我的更新声明。
asp.net/C#告诉我“查询表达式中存在”附加信息:语法错误(缺少运算符)“。
"UPDATE s_transaction_enquiry
SET s_transaction_enquiry.interest_amount = DateDiff('d', s_transaction_enquiry.due_date, Now()) * (s_transaction_enquiry.payment_amount / 100 * sales_ledger.interest_rate)
FROM s_transaction_enquiry JOIN sales_ledger
ON s_transaction_enquiry.account_number=sales_ledger.account_number
WHERE s_transaction_enquiry.status = 'OPEN';
任何人都可以帮忙纠正这个陈述吗?我认为问题可能在于这一行:
// Im trying to calculate the number of days between today's date and the date in the database.
DateDiff('d', s_transaction_enquiry.due_date, Now())
答案 0 :(得分:0)
我认为在MS Access中,当涉及多个表时,SET部分出现在JOIN之后。
尝试这样做
"UPDATE s_transaction_enquiry
JOIN sales_ledger
ON s_transaction_enquiry.account_number=sales_ledger.account_number
SET s_transaction_enquiry.interest_amount = DateDiff('d', s_transaction_enquiry.due_date, Now()) * (s_transaction_enquiry.payment_amount / 100 * sales_ledger.interest_rate)
WHERE s_transaction_enquiry.status = 'OPEN';"
答案 1 :(得分:0)
试试这个:
UPDATE s_transaction_enquiry
INNER JOIN sales_ledger ON s_transaction_enquiry.account_number = sales_ledger.account_number
SET s_transaction_enquiry.interest_amount = (DateDiff("d",[s_transaction_enquiry]![due_date],Now())*([s_transaction_enquiry]![payment_amount]/100*[sales_ledger]![interest_rate]))
WHERE (([s_transaction_enquiry]![status]='Open'));
这在Access中运行时没有错误。