为什么C表白名单客户出不来 SELECT aa.hdrid, aa.dtlid, aa.protype, aa.proname, aa.subproname, aa.proclasee, aa.dutyempcode, aa.dutyempname, a.ownerid, a.saledeptid, a.cstid, b.gkunifygoods, a.goodid, 0 last_qy_billqty, 0 last_qy_SUMVALUE, 0 last_qy_NOTAXMONEY, 0 last_qy_CWCB, a.Y_BILLQTY Y_BILLQTY, A.Y_SUMVALUE_SAL Y_SUMVALUE_SAL, A.Y_NOTAXMONEY_SAL Y_NOTAXMONEY_SAL, A.Y_AVG_CW_SAL Y_AVG_CW_SAL, A.M_BILLQTY M_BILLQTY, A.M_SUMVALUE_SAL M_SUMVALUE_SAL, a.LAST_Y_BILLQTY LAST_Y_BILLQTY, a.LAST_Y_SUMVALUE_SAL LAST_Y_SUMVALUE_SAL, A.LAST_Y_NOTAXMONEY_SAL LAST_Y_NOTAXMONEY_SAL, A.LAST_Y_AVG_CW_SAL LAST_Y_AVG_CW_SAL, A.LAST_M_BILLQTY LAST_M_BILLQTY, A.LAST_M_SUMVALUE_SAL LAST_M_SUMVALUE_SAL FROM ( SELECT b.hdrid, b.dtlid, a.protype, a.proname, b.SUBPRONAME, a.proclasee, a.dutyempcode, a.dutyempname FROM fr_project_hdr a, (SELECT * FROM fr_project_dtl WHERE stopflage='00') b WHERE a.stopflage='00' AND a.id=b.hdrid AND a.if_subpro='10' ${if(len(项目分类) == 0,"","and a.protype in ('" + 项目分类 + "')")} ${if(len(项目类别) == 0,"","and a.proclasee in ('" + 项目类别 + "')")} ${if(len(负责人) == 0,"","and a.dutyempcode in ('" + 负责人 + "')")} ${if(len(项目名称) == 0,"","and a.id in (" + 项目名称 + ")")} ${if(len(子项目名称) == 0,"","and b.dtlid in (" + 子项目名称 + ")")} UNION ALL SELECT a.id, 0 dtlid, a.protype, a.proname, NULL SUBPRONAME, a.proclasee, a.dutyempcode, a.dutyempname FROM fr_project_hdr a WHERE a.stopflage='00' AND a.if_subpro='00' ${if(len(项目分类) == 0,"","and a.protype in ('" + 项目分类 + "')")} ${if(len(项目类别) == 0,"","and a.proclasee in ('" + 项目类别 + "')")} ${if(len(负责人) == 0,"","and a.dutyempcode in ('" + 负责人 + "')")} ${if(len(项目名称) == 0,"","and a.id in (" + 项目名称 + ")")} ${if(len(子项目名称) == 0,"","and b.dtlid in (" + 子项目名称 + ")")} ) aa, fr_d_salewdrvalues a, ( SELECT hdrid, dtlid, GKUNIFYGOODS, goodid, AGPRICE FROM fr_project_goods a, cmsxty.spm_waredict_ext@cx_cms b WHERE a.stopflage='00' AND a.gkunifygoods=b.sinopharm_id ${if(len(项目分类) == 0,"","and a.protype in ('" + 项目分类 + "')")} ${if(len(项目类别) == 0,"","and a.proclasee in ('" + 项目类别 + "')")} ${if(len(负责人) == 0,"","and a.dutyempcode in ('" + 负责人 + "')")} ${if(len(项目名称) == 0,"","and a.hdrid in (" + 项目名称 + ")")} ${if(len(子项目名称) == 0,"","and b.dtlid in (" + 子项目名称 + ")")} ) b--品种 ${IF(1=1, ",(SELECT a.hdrid, a.dtlid, a.GKUNIFYCST, b.cstid FROM fr_project_cst a, (SELECT ID CSTID,SINOPHARM_ID FROM CMSXTY.SPM_PRODUCER_EXT@CX_CMS) b WHERE a.CSTBUTE=2 AND a.hdrid=('" + 项目名称 + "') AND a.dtlid=nvl('" + 子项目名称 + "',0) AND a.GKUNIFYCST=b.SINOPHARM_ID AND a.stopflage='00' ) C" ,"") }--白名单客户 WHERE a.compid=1 AND a.month_id='202212' AND a.day_id='31' AND aa.hdrid=b.hdrid AND aa.dtlid=b.dtlid AND a.goodid=b.goodid ${IF(sql("ztsc","SELECT count(distinct CSTBUTE) from fr_project_cstattribute where 1=1 AND CSTBUTE=2 and stopflage='00'" +IF(LEN(项目名称)==0,""," AND hdrid='"+项目名称+"'")+IF(LEN(子项目名称)=0,""," AND dtlid='"+子项目名称+"'"),1,1)>=1 && sql("ztsc","SELECT count(distinct CSTBUTE) from fr_project_cstattribute where 1=1 AND CSTBUTE=4 and stopflage='00'" +IF(LEN(项目名称)==0,""," AND hdrid='"+项目名称+"'")+IF(LEN(子项目名称)=0,""," AND dtlid='"+子项目名称+"'"),1,1)<1 , "and a.cstid=c.cstid", if(sql("ztsc","SELECT count(distinct CSTBUTE) from fr_project_cstattribute where 1=1 AND CSTBUTE=2 and stopflage='00'" +IF(LEN(项目名称)==0,""," AND hdrid='"+项目名称+"'")+IF(LEN(子项目名称)=0,""," AND dtlid='"+子项目名称+"'"),1,1)>=1 && sql("ztsc","SELECT count(distinct CSTBUTE) from fr_project_cstattribute where 1=1 AND CSTBUTE=4 and stopflage='00'" +IF(LEN(项目名称)==0,""," AND hdrid='"+项目名称+"'")+IF(LEN(子项目名称)=0,""," AND dtlid='"+子项目名称+"'"),1,1)>=1 , "and (a.cstid=c.cstid or a.cstid=d.cstid)",
if(sql("ztsc","SELECT count(distinct CSTBUTE) from fr_project_cstattribute where 1=1 AND CSTBUTE=2 and stopflage='00'" +IF(LEN(项目名称)==0,""," AND hdrid='"+项目名称+"'")+IF(LEN(子项目名称)=0,""," AND dtlid='"+子项目名称+"'"),1,1)<1 && sql("ztsc","SELECT count(distinct CSTBUTE) from fr_project_cstattribute where 1=1 AND CSTBUTE=4 and stopflage='00'" +IF(LEN(项目名称)==0,""," AND hdrid='"+项目名称+"'")+IF(LEN(子项目名称)=0,""," AND dtlid='"+子项目名称+"'"),1,1)>=1 , "and a.cstid=d.cstid", "" ) ) )}--白名单客户关联条件 |