[firebase-br] Incrementador e Decrementador de meses
Luciano
luciano em praticsistemas.com.br
Ter Mar 29 17:36:48 -03 2005
Ao amigo que solicitou veja se isto satisfaz
CREATE PROCEDURE INC_DEC_MES(
WDAT DATE,
WQTD SMALLINT)
RETURNS (
R_INC_DEC_MES DATE)
AS
DECLARE VARIABLE WDIA SMALLINT;
DECLARE VARIABLE WMES SMALLINT;
DECLARE VARIABLE WANO SMALLINT;
DECLARE VARIABLE WINT SMALLINT;
DECLARE VARIABLE WTRM CHAR(2);
DECLARE VARIABLE WTRD CHAR(2);
begin
wdia = extract(day from :wdat);
wmes = extract(month from :wdat);
wano = extract(year from :wdat);
wmes = :wmes + :wqtd;
if (:wqtd > 0) then
begin
while (:wmes > 12) do begin
wano = :wano + 1;
wmes = :wmes - 12;
end
end
else begin
while (:wmes < 1) do begin
wano = :wano - 1;
wmes = :wmes + 12;
end
end
if ((:wmes = 2) and (:wdia > 28)) then
begin
select r_mod from mod(:wano, 4) into :wint;
if ((:wint = 0) and (:wdia > 29)) then
wdia = 29;
else if ((:wint > 0) and (:wdia > 28)) then
wdia = 28;
end
else if (:wdia > 30) then begin
if ((:wmes = 4) or (:wmes = 6) or (:wmes = 9) or (:wmes = 11)) then
wdia = 30;
end
select r_IntZero from IntZero(:wdia, 2) into :wtrd;
select r_IntZero from IntZero(:wmes, 2) into :wtrm;
r_Inc_Dec_Mes = cast(cast(:wano as varchar(4)) || '-' ||
:wtrm || '-' || :wtrd as date);
suspend;
end
Sorte
Luciano C dos Santos
Mais detalhes sobre a lista de discussão lista