Subject Re: [ib-support] Setting a generator to the maximum value of the primary key
Author Lucas Franzen
Stevio schrieb:
>
> Can someone tell me how to fix the following code please?
>
> SET GENERATOR GEN_NEW_AUTHOR_ID TO (SELECT MAX(AUTHOR_ID) FROM AUTHOR);


> I have data that I have migrated from Paradox to InterBase. I am currently
> writing a script with all the updates that I am making to the data, as I
> will have to go through this process again.
>
> I am trying to create primary key generators that are set to the primary key
> value of the last record in the table, but the code above doesn't work.
>
> What is wrong?
> Thanks,
> Stephen

Stephen,

you might try:

SELECT GEN_ID ( GEN_NEW_AUTHOR_ID,
( SELECT MAX ( AUTHOR_ID ) FROM AUTHOR ) + 1 )
FROM RDB$DATABASE
(this is if the current genvalue is 0)


if it isn't 0, use:
SELECT GEN_ID ( GEN_NEW_AUTHOR_ID,
( SELECT MAX ( AUTHOR_ID ) FROM AUTHOR ) + 1
- GEN_ID ( G_NEW_AUTHOR_ID, 0 ) )
FROM RDB$DATABASE

I think the SET GENERATOR command does just accept "plain Integers" as
parameter.


HTH


Luc.



>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/