All pastes #494852 Raw Edit

Miscellany

public sql v1 · immutable
·published 2007-05-18 13:21 UTC
rendered paste body
declare final int(11);declare result int(11);DECLARE done INT DEFAULT 0;      declare cur1 cursor for         select         `view_financeiro_etapas`.`FIET_DT_EMISSAO`,         `view_financeiro_etapas`.`FIET_DT_RECEBIMENTO`,         `view_financeiro_etapas`.`FIET_VL_TOTAL`,         `view_financeiro_etapas`.`FIET_DT_ALTERACAO_EMISSAO`,         `view_financeiro_etapas`.`FIET_DT_RECEBIMENTO_ALTERACAO`,         `view_financeiro_etapas`.`FIET_VL_TOTAL_ALTERACAO`         FROM             `view_financeiro_etapas`         where `view_financeiro_etapas`.`ORSE_CD_ORDEM_SERVICO`=CD_OS         ;DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;-- P4 e suas etapas infinitas      if CD_PROD = 4 then         open cur1;         set result = 0;         REPEAT               FETCH cur1 into fat1,rec1,vl1, altfat1, altrec1, altvl1;         return fat1;               case                   when isnull(fat1) then                        set result =1;                   when isnull(rec1) then                        set result =2;               end case;         UNTIL done end repeat;         if done THEN            set result = result + 2;         end if;                  return result;      end if;-- P4 e suas etapas infinitas