SET TERM ^ ;
ALTER TRIGGER WGHCONTO_STOCLI ACTIVE
AFTER UPDATE POSITION 0
AS
begin
  if(old.flag<6 and new.flag>5) then
    begin
    update wghreg set wghreg.id_conto=0 where id_conto=old.codice;
    update wghsps set wghsps.id_conto=0 where id_conto=old.codice;
    if (new.codcli>0) then
        insert into wghclist (codice,camera,arrivo,partenza,adulti,bambini,tar1,tar2,tar3,trattam,importo,listino,id_ditta,id_dittapren)
            values (new.codcli,new.reccam,new.arrivo,new.partenza,new.adulti,new.bambini,new.tar1,new.tar2,new.tar3,new.trattam,new.saldo,new.listino,new.codditta,new.id_dittapren);
    end
  if(new.flag<99 and new.flag>6) then
    begin
    delete from wghaddsto where wghaddsto.codconto=old.codice;
    delete from wghcontosto where wghcontosto.codice=old.codice;
    insert into wghcontosto select codice,descriz,reccam,codcli,codditta,flag,prestin,tipopag,inuso,codprimo,codsec,valprimo,valsec,acconto,deposito,numrfacc,tar1,tar2,tar3,dal1,dal2,saldo,addauto,trattam,capoconto,sottoconto,sospeso,esborsi,rfditta,imp1,imp2,imp3,imp4,listino,arrivo,partenza,centralino,note_conto,iva1,iva2,iva3,iva4,adulti,bambini,prenotazione,nrpac,pacchetto,canale_v,segmento_m,id_dittapren from wghconto where codice=old.codice;
    insert into wghaddsto select idadd,codconto,codadd,descriz,quantita,valore,data_add,operatore,ora,minuti,data_ins from wghadd where wghadd.codconto=old.codice;
    end
end^
SET TERM ; ^