martes, 19 de mayo de 2015

Consecutive Number of Period in iDempiere


-- select * from sp_reordenar_num_periodo();

-- drop function sp_reordenar_num_periodo();

create or replace function sp_reordenar_num_periodo()
returns boolean
as $$
begin
    drop table if exists tmp_orden_periodo;
   
    create temporary table tmp_orden_periodo as
    select
        row_number() over(order by y.fiscalyear::int asc, p.periodno asc) as corr,
        y.fiscalyear,
        p.periodno,
        p.name,
        p.c_period_id
    from c_period p
        join c_year y
        on p.c_year_id = y.c_year_id
    where p.ad_client_id = 1000001;

    update c_period
        set periodno =
        (select op.corr from tmp_orden_periodo op
        where op.c_period_id = c_period.c_period_id);
   
    return true;
end;
$$ language plpgsql;


No hay comentarios:

Publicar un comentario