我不知道如何问这个问题,但这里有。我正在尝试编写一个每晚运行的程序来检查企业的所有未付发票,然后在需要时添加服务费。我需要查询未付发票,然后检查创建日期和当前日期之间的 datediff(),然后在某些值(例如 15 天或 30 天)处,我需要对其他表进行多次插入和更新,以添加服务费和更新余额。从我读到的内容来看,循环不是要走的路,但我不确定如何跟踪当前发票或在大型更新语句中如何插入。这是我需要的一些伪代码
select * from invoice where ispaid = 0
set days = currentdate - invoicecreationdate
switch (days)
case 30
insert servicecharge
update invoice
update balance
case 60
insert servicecharge
update invoice
update balance due
case 90
insert servicecharge
update invoice
update balance
我知道这没什么好做的,但我会尽我所能获得帮助。我不确定这在没有循环的情况下如何工作,因为在每种情况下我都有几条语句要运行,这些语句需要知道我们当前正在处理的发票