SELECT SUBSTR(a.dbilldate,0,4) nianfen, SUBSTR(a.dbilldate,1,7) yuefen, (CASE WHEN substr(substr(A.dbilldate, 1, 10), 9, 2) <= 10 THEN '上旬' WHEN 11 <= substr(substr(A.dbilldate, 1, 10), 9, 2) AND substr(substr(A.dbilldate, 1, 10), 9, 2) <= 20 THEN '中旬' WHEN 21 <= substr(substr(A.dbilldate, 1, 10), 9, 2) AND substr(substr(A.dbilldate, 1, 10), 9, 2) <= 31 THEN '下旬' ELSE '0' END) dingdanriq, D.code wljbflbm, D.name wlflmc, A.nnum zhusl, B.name jldw, A.norigtaxmny yuanbijshj, A.ntaxmny benbijshj, substr(A.dbilldate, 1, 10) riqi FROM po_order_b A LEFT JOIN bd_measdoc B ON A.cunitid = B.pk_measdoc LEFT JOIN bd_material C ON A.pk_srcmaterial =C.pk_material LEFT JOIN bd_marbasclass D ON C.pk_marbasclass = D.pk_marbasclass LEFT JOIN org_purchaseorg E ON A.pk_org =E.pk_purchaseorg WHERE A.dr = '0' AND D.code='040102001001' or D.code='040102001002' or D.code='040101001001' or D.code='040101001002' and 1=1 ${if(len(开始日期)==0,"","and substr(a.dbilldate,1,7) >= '"+开始日期+"'")} ${if(len(结束日期)==0,"","and substr(a.dbilldate,1,7) <= '"+结束日期+"'")} order by A.dbilldate