Files
Customer/CONN/Once/Afm#bestellingen.sql
Arthur Egberink 9fbf668b41 CONN#12089
svn path=/Customer/trunk/; revision=13152
2007-01-04 12:17:08 +00:00

78 lines
2.3 KiB
SQL

-- Script om bestelopdrachten automatisch af te melden
-- (c) 2005-2006 Dijkoraad IT bv
-- $Revision: 1 $
-- $Modtime: 4-01-07 14:12 $
--
-- Support: +31 53 4800700
DECLARE
CURSOR c_cursor
IS
SELECT DISTINCT bes_bestelopdr_key
FROM bes_bestelling b,
bes_bestelling_item bi,
bes_bestelopdr_item boi
WHERE bes_bestelling_status = 5
AND b.bes_bestelling_key = bi.bes_bestelling_key
AND bes_bestelling_datum < SYSDATE - 40
AND bi.bes_bestelopdr_item_key = boi.bes_bestelopdr_item_key;
CURSOR c_cursor2 (pBestelopdr_key IN NUMBER)
IS
SELECT boi.bes_bestelopdr_item_key, bi.bes_bestelling_item_key
FROM bes_bestelling_item bi,
bes_bestelopdr_item boi
WHERE bi.bes_bestelopdr_item_key = boi.bes_bestelopdr_item_key
AND boi.bes_bestelopdr_key = pBestelopdr_key;
next_record c_cursor%ROWTYPE;
next_record2 c_cursor%ROWTYPE;
oracle_err_num NUMBER;
oracle_err_mes VARCHAR2 (200);
v_errormsg VARCHAR2 (1024);
BEGIN
FOR next_record IN c_cursor LOOP
BEGIN
FOR next_record2 IN c_cursor2(next_record.bes_bestelopdr_key) LOOP
BEGIN
UPDATE bes_bestelopdr_item b
SET bes_bestelopdr_item_aantalontv = bes_bestelopdr_item_aantal
,bes_bestelopdr_item_ontvangen = SYSDATE
WHERE bes_bestelopdr_item_key = next_record2.bes_bestelopdr_item_key;
UPDATE bes_bestelling_item
SET BES_BESTELLING_ITEM_AANTALONTV = bes_bestelling_item_aantal
WHERE bes_bestelling_item_key = next_record2.bes_bestelling_item_key;
EXCEPTION
WHEN OTHERS
THEN
oracle_err_num := SQLCODE;
oracle_err_mes := SUBSTR (SQLERRM, 1, 100);
v_errormsg :=
'(ORACLE error ' || oracle_err_num || '/' || oracle_err_mes
|| ')';
END;
END LOOP;
END;
END LOOP;
commit;
END;
/