红框部分有问题,删掉后可以正常跑出结果,不知道哪里错了 改成t5也不行。。。 select a.[fd_id],krm.fd_number,fd_heTongHao,[fd_gongYingShangMingChen1],[fd_heTongMingChen],[fd_heZuoLeiXing],[fd_shouKuanFangShi],[fd_shouKuanGuiZe],[fd_heTongYouXiaoQiKaiShi],[fd_heTongZongJinE] ,[fd_heTongYouXiaoQiJieShu],[fd_shiFuXuYue],[fd_zhangQi],[fd_yueDingShouKuanShiJian1],iif([fd_shiFuWeiTeHui] = '0','否',iif([fd_shiFuWeiTeHui] = '1','是','')) 特惠,t.总金额 ,iif((select ([fd_heTongYouXiaoQiJieShu])-(select (getdate())))<=0,'已到期' ,iif((select ([fd_heTongYouXiaoQiJieShu]))-(select (getdate()))<=30 ,'即将到期','')) 合同到期提醒,t5.状态 from [dbo].[ekp_kehuht] a inner join km_review_main krm on a.fd_id = krm.fd_id left join ( select [fd_guanLianHeTong] ,sum([DocTotal]) 总金额 from [dbo].[ekp_LXSQD] a inner join [dbo].[km_review_main] krm on a.fd_id = krm.fd_id left join [View_sap_OQUT] as b on a.[fd_xiangMuHao] = b.[U_PM_Code] left join ( select t0.* from (select qwe.fd_number 单号,abc.[fd_fact_node_id] 状态 from (select fd_number,[fd_fact_node_id],fd_create_time from [lbpm_audit_note] a inner join km_review_main krm on a.fd_process_id = krm.fd_id where fd_number like '%KHHT%' ) abc right join (select fd_number,max(fd_create_time) 时间 from [lbpm_audit_note] a inner join km_review_main krm on a.fd_process_id = krm.fd_id where fd_number like '%KHHT%' GROUP BY fd_number) qwe on abc.fd_number = qwe.fd_number and abc.fd_create_time = qwe.时间) t0 ) t5 on t5.单号 = krm.fd_number where [doc_status] not in ('10','00') and [fd_guanLianHeTong] is not null group by [fd_guanLianHeTong] ) t on t.[fd_guanLianHeTong] = fd_number where [doc_status] not in ('10','00') |