Subject Re: [firebird-support] help Store Procedure
Author Helen Borrie
At 09:30 PM 29/11/2003 +0000, you wrote:
>Wrong ?
>
>CREATE PROCEDURE SP_INC (
> SUCUR INTEGER,
> INCREMENTO DECIMAL (2, 2))
>AS
>BEGIN
>if (incremento <> 0) then
>
> BEGIN

I see two problems with this line:

> UPDATE SUC_ART SET PRECIO=PRECIO*:INCREMENTO

First, INCREMENTO has two places of decimal, so you will need to CAST the
result of the multiplication back to the correct scale for PRECIO (let's
assume PRECIO is DECIMAL(18,2).

Next, the calculation will update the price to a *fraction* of its starting
value. Surely you don't want that?

Shouldn't this be:
UPDATE SUC_ART
SET PRECIO=PRECIO + CAST((PRECIO * :INCREMENTO) AS DECIMAL(18,2);

> WHERE ID_SUC= :SUCUR ;
> SUSPEND; <------------------remove this - suspend is used for making
> output sets.
> END
>END


>I must run a store procedure than update al the recordos from a
>SUCURSAL and increment the PRICE (PRECIO) with a PORCENT
>I don't know whats wrong with this?


\heLen