create view vwtrimestre (
TRI1_INI,
TRI1_FIM,
TRI2_INI,
TRI2_FIM,
TRI3_INI,
TRI3_FIM,
TRI4_INI,
TRI4_FIM,
DATA,
TRIMESTRE
)
as
select
    A.*,
    current_date as DATA,
    iif(current_date between TRI1_INI and TRI1_FIM, 1,
    iif(current_date between TRI2_INI and TRI2_FIM, 2,
    iif(current_date between TRI3_INI and TRI3_FIM, 3,
    iif(current_date between TRI4_INI and TRI4_FIM, 4, 0)))) as TRIMESTRE
from(
    select
        cast(fn_start_of_month_2('01.01.'||extract(year from current_date )) as date) TRI1_INI,
        cast(fn_end_of_month_2('01.03.'||extract(year from current_date )) as date) TRI1_FIM,
    
        cast(fn_start_of_month_2('01.04.'||extract(year from current_date )) as date) TRI2_INI,
        cast(fn_end_of_month_2('01.06.'||extract(year from current_date )) as date) TRI2_FIM,
    
        cast(fn_start_of_month_2('01.07.'||extract(year from current_date )) as date) TRI3_INI,
        cast(fn_end_of_month_2('01.09.'||extract(year from current_date )) as date) TRI3_FIM,
    
        cast(fn_start_of_month_2('01.10.'||extract(year from current_date )) as date) TRI4_INI,
        cast(fn_end_of_month_2('01.12.'||extract(year from current_date )) as date) TRI4_FIM
    from RDB$DATABASE
) A
;

