DELETE FROM DC2.OR_100 WHERE PV_USER = '413';
commit;
INSERT INTO DC2.OR_100 (PV_KEY,PV_USER,PV1)
SELECT LPAD(TO_CHAR(ROWNUM),20,0),TABLE_SELECT.* FROM (
SELECT '413',COUNT(*)
FROM
DC2_DEMO.SAM_DENPYO T001
LEFT OUTER JOIN DC2_DEMO.SAM_SYOHIN T002 ON
 T001.DEN_SYO_CD=T002.SYO_CD
LEFT OUTER JOIN DC2_DEMO.SAM_DAY T007 ON
 T001.DEN_DATE=T007.HIDUKE
LEFT OUTER JOIN DC2_DEMO.SAM_TORIHIKI T006 ON
 T001.SOUKO=T006.TOR_CD
 AND T006.TOR_KB='0'
LEFT OUTER JOIN DC2_DEMO.SAM_TORIHIKI T004 ON
 T002.SHI_CD=T004.TOR_CD
 AND T004.TOR_KB='1'
WHERE
 T001.DEN_KB='2'
 AND T007.NENGETSU BETWEEN '20090101' AND '20091201'
) TABLE_SELECT
;
commit;
EXIT;


