miércoles, 25 de enero de 2012

Obtener fecha de vencimiento


-- Function: fnt_left(character varying, integer)

-- DROP FUNCTION fnt_left(character varying, integer);

CREATE OR REPLACE FUNCTION fnt_left(character varying, integer)
  RETURNS character varying AS
$BODY$
begin

    return substring($1, 1, $2);

end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION fnt_left(character varying, integer)
  OWNER TO adempiere;

-- Function: get_fvencimiento(character varying)

-- DROP FUNCTION get_fvencimiento(character varying);

CREATE OR REPLACE FUNCTION get_fvencimiento(character varying)
  RETURNS character varying AS
$BODY$
declare
    texto character varying;
begin
    texto = substring($1, position('_' in $1) + 1, length($1));

    if((position('_' in texto) - 1) < 0)then
        texto = 'N/A';
    else
        texto = fnt_left(texto, position('_' in texto) - 1);
    end if;
   
    return texto;
end;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION get_fvencimiento(character varying)
  OWNER TO adempiere;

No hay comentarios:

Publicar un comentario