[firebase-br] execute statement

CLEITON MACIEL REIS DA SILVA cleitonmaciell em gmail.com
Qua Nov 4 10:56:47 -03 2009


Olá bom dia a todos.

Galera quando eu depuro essa procedure no IBExpert ela roda blz. Mas quando
eu executo pra valer ela causa um exceção.

-------------------------------------------------------------------------------------------------------------------------------

Unsuccessful execution caused by an unavailable  resource.

Variable type (position 0) in EXECUTE STATEMENT 'select
gen_id(numero_nf_emp_1,1' INTO does not match returned

column type.

At procedure 'SP_NUMERA_NF'

-------------------------------------------------------------------------------------------------------------------------------





-- essa procedure tem a funcção de gerar o numero de nota fiscal de acordo a
empresa selecionada. Por isso uso a variavel no select do generator.


CREATE PROCEDURE SP_NUMERA_NF (

    tabela varchar(30),

    xemp integer)

returns (

    notafiscal integer)

as

declare variable ult_nf integer;

declare variable ult_vda integer;

declare variable ult_outvda integer;

declare variable ult_devvda integer;

declare variable ult_devcpa integer;

declare variable nvenda integer;

declare variable noutvenda integer;

declare variable ndevvenda integer;

declare variable ndevcpa integer;

begin

   execute statement

    'select gen_id(numero_nf_emp_'||:xemp||',1) as ULT_NF from RDB$DATABASE'
into :notafiscal;    -- quero retornar o numero gerado aqui.

-- Aqui ele gerar o proximo numero de nota
fiscal.




   ult_nf = notafiscal;



  -- exception teste;



   select first 1 v.notafiscal, v.venda   from vendas v      where
v.empresa  = :xemp and v.notafiscal = :notafiscal and v.serie = 'NF' into
:ult_vda, :nvenda;

   select first 1 ov.notafiscal, ov.venda from out_vendas ov where
ov.empresa = :xemp and ov.notafiscal = :notafiscal and ov.serie = 'NF' into
:ult_outvda, :noutvenda;

   select first 1 dv.notafiscal, dv.venda from dev_vendas dv where
dv.empresa = :xemp and dv.notafiscal = :notafiscal and dv.serie = 'NF' into
:ult_devvda, :ndevvenda;

   select first 1 dc.numero_nf_entrada, dc.compra from devcompras dc where
dc.empresa = :xemp and dc.numero_nf_entrada = :notafiscal and dc.serie =
'NF' into :ult_devcpa, :ndevcpa;



-- aqui ele vai procurar já existe algum registro com o numero de nota
fiscal gerado



   if (notafiscal = ult_vda) then

   begin

      execute statement

      'select gen_id(numero_nf_emp_'||:xemp||',-1) as ULT_NF from
RDB$DATABASE' into :ult_nf;

      exception numero_utilizado ' A NOTA FISCAL '||cast(notafiscal as
varchar(10))||' pertence a VENDA ['||cast(nvenda as varchar(20))||']';

   end



   if (notafiscal = ult_outvda) then

   begin

      execute statement

      'select gen_id(numero_nf_emp_'||:xemp||',-1) as ULT_NF from
RDB$DATABASE' into :ult_nf;

      exception numero_utilizado ' A NOTA FISCAL '||cast(notafiscal as
varchar(10))||' pertence a OUTRAS SAIDA, PEDIDO: ['||cast(noutvenda as
varchar(20))||']';

   end



   if (notafiscal = ult_devvda) then

   begin

      execute statement

      'select gen_id(numero_nf_emp_'||:xemp||',-1) as ULT_NF from
RDB$DATABASE' into :ult_nf;

      exception numero_utilizado '  A NOTA FISCAL '||cast(notafiscal as
varchar(10))||' pertence a DEVOLUÇÃO de venda, PEDIDO: ['||cast(ndevvenda as
varchar(20))||']';

   end



   if (notafiscal = ult_devcpa) then

   begin

      execute statement

      'select gen_id(numero_nf_emp_'||:xemp||',-1) as ULT_NF from
RDB$DATABASE' into :ult_nf;

      exception numero_utilizado ' A NOTA FISCAL '||cast(notafiscal as
varchar(10))||' pertence a DEVOLUÇÃO DE COMPRA : '||cast(ndevcpa as
varchar(20))||']';

   end

   suspend;

end





o que pode esta errado, se na depuração passa e quando ela é excutada com F9
ela ocorre erro.

Existe algo errado no execute statement?



Abraço galera.

_____________________________
Qualisoft Automação Comercial
Barreiras - Bahia
Cleiton Maciel



Mais detalhes sobre a lista de discussão lista