ALTER TABLE TBPDV_CONFERENCIA_ITEM
    ADD DATA DATE;

CREATE INDEX ITBPDV_CONFERENCIA_ITEM_10
ON TBPDV_CONFERENCIA_ITEM (DATA);

CREATE INDEX ITBPDV_CONFERENCIA_ITEM_11
ON TBPDV_CONFERENCIA_ITEM (USUARIO_ID);


SET TERM ^ ;

CREATE OR ALTER trigger ttbpdv_conferencia_item_b05i for tbpdv_conferencia_item
active before insert position 5
AS
BEGIN
    IF(NEW.USUARIO_ID = 0) THEN
    BEGIN
        NEW.USUARIO_ID = FN_CURRENT_USER_ID();
    END

    NEW.DATA = CAST(NEW.DATAHORA AS DATE);
END
^

SET TERM ; ^

UPDATE TBPDV_CONFERENCIA_ITEM T SET T.DATA = CAST(T.DATAHORA AS DATE);
