请教sqlserver问题,无法绑定由多个部分组成的标识符

image.png

image.png

红框部分有问题,删掉后可以正常跑出结果,不知道哪里错了

image.png

改成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')

用户m2896739 发布于 2021-8-11 14:07 (编辑于 2021-8-11 14:30)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共3回答
最佳回答
0
StudyYLLv6初级互助
发布于2021-8-11 14:35

image.png

红框部分移到蓝框出,红框部分的left join 好像没什么用,然后t0.状态改成t5.状态

  • 用户m2896739 用户m2896739(提问者) 厉害!!解决了,太感谢了
    2021-08-11 14:39 
  • StudyYL StudyYL 回复 用户m2896739(提问者) 或者你在t那边把状态字段也写出来,但是group by也要加上 t5.状态。然后t0.状态改成t.状态不知道这样汇总有没有影响结果,毕竟汇总方式不一样了。你试试看 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 ,\'即将到期\',\'\')) 合同到期提醒,t.状态 from [dbo].[ekp_kehuht] a inner join km_review_main krm on a.fd_id = krm.fd_id left join ( select [fd_guanLianHeTong],t5.状态 ,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],t5.状态 ) t on t.[fd_guanLianHeTong] = fd_number where [doc_status] not in (\'10\',\'00\')
    2021-08-11 14:50 
最佳回答
0
Z4u3z1Lv6专家互助
发布于2021-8-11 14:12(编辑于 2021-8-11 14:25)

是不是还少了个逗号

image.png

改成T5.状态

image.png

最佳回答
0
烟尘Lv6高级互助
发布于2021-8-11 14:18(编辑于 2021-8-11 14:40)

image.png

状态没有传到最外一层的查询,需要从t5传到t,照截图改一下试试

  • 用户m2896739 用户m2896739(提问者) 好像不是括号的问题,删掉红框的部分,能返回结果
    2021-08-11 14:21 
  • 烟尘 烟尘 回复 用户m2896739(提问者) t5.状态改成t.状态
    2021-08-11 14:36 
  • 3关注人数
  • 507浏览人数
  • 最后回答于:2021-8-11 14:40
    请选择关闭问题的原因
    确定 取消
    返回顶部