请注意,对于每张CardNo我想要最小日期的extraamt和当前日期的pendamt + trnamt并将它们的总和放入Recamt中,并且您想要使用我使用的相同Recamt值更新CardNo的所有行此更新查询相同,但它抛出以下错误: 子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。
查询是:
update Tbl_Emi set RecAmt =
(
select
(select extraamt from Tbl_Emi e1 where LastRecDate=(SELECT MIN(lastrecdate) FROM Tbl_Emi) and e1.CardNo=e.CardNo )
+
(select pendamt+trnammt from Tbl_Emi e2 where LastRecDate=(CAST(GETDATE() AS DATE)) and e2.CardNo=e.CardNo )
from Tbl_Emi e where e.lastrecdate=(CAST(GETDATE() AS DATE))
)
where CardNo=
(
select
(select CardNo from Tbl_Emi e2 where LastRecDate=(CAST(GETDATE() AS DATE)) and e2.CardNo=e.CardNo)
from Tbl_Emi e where e.lastrecdate=(CAST(GETDATE() AS DATE))
)
and lastrecdate=(CAST(GETDATE() AS DATE))