select --2019 as iyear, a.ywyid,d.name ywymc --a.cpx,a.cpxmc --,CAST(ISNULL(g.rwe,'0') as varchar) into ydbymbe_lt1 from ( select a.ywyid,b.id cpx,b.showvalue cpxmc-- into aaa from NSC_A8_renwufenjiecengji a left join NSC_A8_changpinxian b on 1=1 ) a left join mbe_lt201911411411140 c on c.ywyid = a.ywyid and c.cpxmc = a.cpxmc left join ( select d.iyear,d.ywyid,d.cpxmc,cast(sum(isnull(d.rwe,0)) as money) rwe from( select a.iyear,a.ywyid,isnull(c.showvalue,'') xzyf,isnull(b.cpx,'') cpxmc, b.je rwe from NSC_A8_yiqixiaoshoujihuashenqingzb a left join NSC_A8_yiqixiaoshoujihuashenqingmx b on a.id = b.formmain_id left join NSC_A8_xinzengshijian c on c.id = b.xzsj where c.showvalue<= 9 )d group by d.iyear,d.ywyid,d.cpxmc )g on g.ywyid = a.ywyid and g.cpxmc = a.cpxmc left join NSC_A8_member_department d on d.id = a.ywyid
利用排除法 确定 d.name 这个字段出现时报这个错误,有可能 和关联
left join NSC_A8_member_department d on d.id = a.ywyid
有关
NSC_A8_member_department ID字段是bigint 类型
NSC_A8_renwufenjiecengji ywyid字段是varchar 类型
两个字段类型不同导致错误
修改NSC_A8_renwufenjiecengji ywyid数据类型后,解决报错问题
select field0001 ywybm, --业务员编码 CAST(field0002 as bigint) ywyID, --业务员名称 field0003 zgbm, --主管编码 field0004 zgmc, --主管名称 field0005 jlbm, --经理编码 field0006 jlmc, --经理名称 field0007 fzbm, --副总编码 field0008 fzmc, --副总名称 field0009 zjlbm, --总经理编码 field0010 zjlmc, --总经理名称 field0011 bmbm, --部门编码 field0012 bmmc --部门名称 from OA70.dbo.formmain_0061