--
-- Name: plan_request_chagestate(); Type: FUNCTION; Schema: public; Owner: postgres
--
CREATE or replace FUNCTION plan_request_chagestate() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
Declare	sqltext varchar; 
BEGIN

	perform public.sp_setstatuses(New.PlanID);

	Return New;

END;
$$;



--
-- Name: plan_request_chagestate; Type: TRIGGER; Schema: public; Owner: sa
--
DO 
$$ 
BEGIN 
IF EXISTS(SELECT * 
                     FROM information_schema.triggers 
                     WHERE event_object_table = lower('T_PLAN_REQUEST') 
                     AND trigger_name = lower('plan_request_chagestate')
                    ) 
                    THEN 
                    DROP TRIGGER plan_request_chagestate ON FIES.T_PLAN_REQUEST;
    END IF ; 

END; 
$$ ;

CREATE TRIGGER plan_request_chagestate AFTER UPDATE OF Status ON FIES.T_PLAN_REQUEST FOR EACH ROW EXECUTE PROCEDURE plan_request_chagestate();
