Subject | Stored Procedure |
---|---|
Author | Jorez A. Nasato |
Post date | 2002-12-12T18:43:49Z |
Hi!
I need a sp that returns 1 (one) value from a table, and this value can't be null, I'm sending my script and if someone could help saying where is my mistake it will be good.
I would like ask for sorry for my english because I'm from Brazil.
Thanks
My script:
SET TERM !! ;
CREATE PROCEDURE SP_BUSCA_VALOR_CH (
DATA_CH DATE,
CONVENIO_CH INTEGER)
RETURNS (
VALOR_CH FLOAT)
AS
begin
select
cast(ch.ch_valor as decimal(4,4))
from
ch
where
( ch.ch_convenio = :convenio_ch ) and
( ch.ch_data <= :data_ch )
order by
ch.ch_data desc
into :valor_ch;
if ( (:valor_ch is null) or (:valor_ch = 0) ) then
begin
select
cast(ch.ch_valor as decimal(4,4))
from
ch
where
( ch.ch_convenio = :convenio_ch )
order by
ch.ch_data desc
into :valor_ch;
if ( :valor_ch is null ) then
begin
valor_ch = 0;
end
end
suspend;
exit;
end!!
SET TERM ; !!
[Non-text portions of this message have been removed]
I need a sp that returns 1 (one) value from a table, and this value can't be null, I'm sending my script and if someone could help saying where is my mistake it will be good.
I would like ask for sorry for my english because I'm from Brazil.
Thanks
My script:
SET TERM !! ;
CREATE PROCEDURE SP_BUSCA_VALOR_CH (
DATA_CH DATE,
CONVENIO_CH INTEGER)
RETURNS (
VALOR_CH FLOAT)
AS
begin
select
cast(ch.ch_valor as decimal(4,4))
from
ch
where
( ch.ch_convenio = :convenio_ch ) and
( ch.ch_data <= :data_ch )
order by
ch.ch_data desc
into :valor_ch;
if ( (:valor_ch is null) or (:valor_ch = 0) ) then
begin
select
cast(ch.ch_valor as decimal(4,4))
from
ch
where
( ch.ch_convenio = :convenio_ch )
order by
ch.ch_data desc
into :valor_ch;
if ( :valor_ch is null ) then
begin
valor_ch = 0;
end
end
suspend;
exit;
end!!
SET TERM ; !!
[Non-text portions of this message have been removed]