/* Formatted on 2020/12/08 17:31:50 (QP5 v5.326) */ SELECT DISTINCT head.VBILLCODE AS 单据号, head.DBILLDATE AS 单据日期, head.CBILLTYPECODE AS 业务类型, head.cothercorpid, bcb.BODYNAME AS 库存组织, bsd.STORNAME AS 门店 FROM ic_general_h head LEFT JOIN ic_general_b body ON head.cgeneralhid = body.cgeneralhid LEFT JOIN ic_general_bb3 bb3 ON body.cgeneralbid = bb3.cgeneralbid AND bb3.dr = 0 LEFT JOIN to_bill tobill ON body.cfirstbillhid = tobill.cbillid LEFT JOIN bd_calbody bcb ON head.cothercalbodyid = bcb.PK_CALBODY LEFT JOIN bd_stordoc bsd ON head.cotherwhid = bsd.PK_STORDOC WHERE head.dr = 0 AND body.dr = 0 AND (head.fbillflag = 3 OR head.fbillflag = 4) AND NVL (head.dr, 0) = 0 AND NVL (body.dr, 0) = 0 AND head.cbilltypecode = '4Y' AND NVL (bb3.dr, 0) = 0 AND body.isok = 'N' AND body.noutnum IS NOT NULL AND NVL (body.btou8rm, 'N') = 'N' AND NOT EXISTS (SELECT 1 FROM ic_general_b WHERE csourcetype = '4Y' AND ic_general_b.csourcebillbid = body.cgeneralbid AND NVL (dr, 0) = 0) AND head.cbilltypecode = '4Y' AND (head.dbilldate >= '2014-01-01') -- AND (head.dbilldate <= '2022-10-27') AND (cbilltypecode = '4Y') ORDER BY 单据日期 DESC