I have a table called patient with four fields called office1, office2, office3 and office4. There is a job that runs at not that puts the value 'BAL' in one of those fields. Sometimes it puts the value in office1 sometimes in office2. My point is it is not always in the same field. It used to always put it in office4. This ment a patient had a balance on their account. The cashiers wanted me to write a trigger that if they paid there balance it removed the 'BAL' value from patient.office4. So I wrote that trigger and it works.:
this only works when the 'BAL' value is in the office4 field. Now I need to re-write the trigger so if 'BAL is in office1 it removes the 'BAL' value from office1, but if the 'BAL' value is in office2 it removes it from there, and so on and so on. So my first attempt was this:Code:CREATE OR REPLACE TRIGGER AXIUM."RMVBALTRG" BEFORE UPDATE OF "LastPaymentAmount" ON "PATIENT" REFERENCING NEW AS NEW FOR EACH ROW DECLARE v_bal NUMBER(10); BEGIN update PTBAL_TMP set "Sum" = (Select sum("Sum" - :NEW."LastPaymentAmount" ) from ptbal_tmp where "Patient" = :NEW."Patient") where "Patient"= :NEW."Patient"; select "Sum" into v_bal from PTBAL_TMP where "Patient"=:NEW."Patient" ; IF (v_bal <=0) THEN :NEW."Office4" := ' '; END IF; exception when others then null; END; /
but the trigger does not compile it gives me this error:Code:CREATE OR REPLACE TRIGGER AXIUM."RMVBALTRG" BEFORE UPDATE OF "LastPaymentAmount" ON "PATIENT" REFERENCING NEW AS NEW FOR EACH ROW DECLARE v_bal NUMBER(10); BEGIN update PTBAL_TMP set "Sum" = (Select sum("Sum" - :NEW."LastPaymentAmount" ) from ptbal_tmp where "Patient" = :NEW."Patient") where "Patient"= :NEW."Patient"; select "Sum" into v_bal from PTBAL_TMP where "Patient"=:NEW."Patient" ; IF (v_bal <=0) THEN If "Office1" = 'BAL' THEN :NEW."Office1" := ' '; elsif "Office2" = 'BAL' THEN :NEW."Office2" := ' '; ELSIF "Office3" = 'BAL' THEN :NEW."Office3" := ' '; END IF; END IF; exception when others then null; END; /
identifier 'office1' must be declared.
I tried adding the table to the code like this If "PATIENT"."Office1" = 'BAL' THEN
but then it errors with table, view or sequence reference 'PATIENT.Office1' not allowed in this context. Am I even approaching this change correctly or am I way off in how I need to re-write this trigger. Any help would be greatly appreciated.


Reply With Quote
Bookmarks