Hi Paul,

You want to say that I need a begin transaccion and commit ?

Thank's for answer me Paul

Hugo

De: "Paul" <paul.hill@hoist-technology.com>
Asunto: Re: How can I get a consecutive unique !!
Fecha: viernes, 08 de enero de 2010 04:32 a.m.

On 07/01/2010 22:18, Hugo Glez. Macias wrote:
> Hi,
>
> I need to get a consecutive number unique for Appointments, and I have
> the next code, but when 4 or more users give appointments at the same
> time, repeats the number to 2 users, some times happens but happens.
> this is my code
> the field is "prog_cita" and the table is "ctrl"
>
> FUNCTION get_cons_appoint
> lccomand = 'select prog_cita from CTRL'
> prmRSTempR = CREATEOBJECT("ADODB.RecordSet")
> lret = prmRSTempR.OPEN(lccomand,lcCnx)
> IF NOT prmRSTempR.eof()
> lnprog_cita = prmRSTempR.Fields(0).Value + 1
>
> lcCommand = "update ctrl set prog_cita = " + ALLTRIM(STR(lnprog_cita))
> IF prmRSTempR.state = 1
> prmRSTempR.CLOSE()
> ENDIF
> prmRSTempR.OPEN(lcCommand, lcCnx)
>
> ENDIF
>
> RETURN lnprog_cita

Hi Hugo,

Run the update first and then read the new value. e.g.

update ctrl set prog_cita = prog_cita + 1
select prog_cita from ctrl

--
Paul