On Mon, Dec 30, 2013 at 10:33 AM, Frank Taylor <[email protected]> wrote:

> Which brings forth this question, where can I see or select from a system
> table that will show what the last Autonumber was for the table, thus allow
> me to check to see if the max(autonumbered col) in a table is greater then
> what the system shows for that table and would generate at insert
>

Frank,

Happy New Year!

SET VAR vTableName TEXT = 'YourTableName'
SET VAR vColumnName TEXT = 'YourAutonumColName'

SELECT d1.SYS_NEXT FROM Sys_Defaults d1, Sys_Columns c2, Sys_Tables t3 +
  WHERE d1.sys_column_id = c2.sys_column_id +
    AND c2.sys_table_id = t3.sys_table_id +
    AND t3.sys_table_name = .vTableName +
    AND c2.sys_column_Name = .vColumnName

SELECT MAX ( &vColumnName ) FROM &vTableName

These two queries give you the "next" number to be autoassigned, and the
current highest value.

You could create a cursor to find all the sys_column_ids  where
SYS_DEFAULT.Column _ID is not null, and look up the current maxes for those
columns.

Bill

Bill

Reply via email to