Hi, I am new to MAXDB functions, today I tried to create one that:

1) updates a table and increments a certain column value
2) returns a string that incorporates that value, combined with
another piece of data

The thing is that I execute a simple update to increment the value by
1, but it get incremented by 2!!!

I am missing something, any help will be appreciated.

I am using MaxDB 7.6.0.34 on WinXP SP1.

The code:

CREATE FUNCTION XXX.getNumCorrespE (dependencia_id INTEGER) RETURNS VARCHAR AS

   VAR ano INTEGER; cnum INTEGER; retval VARCHAR(20);

TRY

 SET ano = 0;
 SET cnum = 0;

update XXX.dependencia set num_corresp_e = num_corresp_e + 1
where dependencia_id = :dependencia_id;

DECLARE functionresult CURSOR FOR

select
   ano,
   num_corresp_e cnum
from XXX.dependencia
where
dependencia_id = :dependencia_id;

WHILE $rc = 0 DO BEGIN
     FETCH functionresult INTO :ano, :cnum;
   END;
CATCH
 IF $rc <> 100 THEN STOP ($rc, 'unexpected error');
CLOSE functionresult;

set retval = chr(ano) || '-' || LFILL(chr(cnum),'0',6);

RETURN retval;


Regards,
Martin Cordova
--
Dinamica - RADical J2EE framework
open source, easy and powerful
http://www.martincordova.com

--
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to