为什么这段代码会插入2行,搞不懂!
INSERT INTO InterestReceive(ContractNm,PeriodRepyDate,RepayType,RepayAmount,receivableAmount)
SELECT a.ContractNm,getdate(),'PeriodOverdueCharge' RepayType,CASE WHEN a.RepayAmount*b.OverdueRate/365*Datediff(day,PeriodRepyDate,getdate())<150 THEN 150 ELSE a.RepayAmount*b.OverdueRate/365*Datediff(day,PeriodRepyDate,getdate()) END RepayAmount,NULL FROM
(
SELECT ContractNm,SUM(ISNULL(receivableAmount,0))receivableAmount,SUM(ISNULL(RepayAmount,0))RepayAmount,PeriodRepyDate FROM InterestReceive WHERE DATEDIFF(day,PeriodRepyDate,GETDATE())>5
AND RepayType IN ('PeriodCapital','PeriodInterst','PeriodMangeCharge') GROUP BY ContractNm,PeriodRepyDate
) AS a
LEFT JOIN OPSInf b ON b.LoanNm=a.ContractNm
WHERE a.receivableAmount=0
(2 行受影响)
------解决方案--------------------
看看结果集和你需要查到的数据有什么不符合的,把哪条去掉。