FUNCTION NewId LPARAMETER tcIdField && field or key to increment LOCAL lcFieldName, lnConnHandle, lnNewId, lnOrigArea, lnRetVal lcFieldName = UPPER(tcIdField) lnOrigArea = SELECT(0) && area to return to lnConnHandle = DefaultConnection() && get connection handle IF lnConnHandle<0 RETURN -1 ENDIF TEXT TO lcSQLCmd TEXTMERGE NOSHOW DECLARE @newId INT WHILE (1=1) BEGIN UPDATE UniqueId SET @newId=nLastNumber+1, nLastNumber=nLastNumber+1 WHERE UPPER(cFieldName)='<<lcFieldName>>' IF @@ROWCOUNT>0 BEGIN BREAK END END SELECT @newId AS nNewNumber ENDTEXT =SQLEXEC(lnConnHandle,lcSQLCmd,'NewIdTemp') =SQLDISCONNECT(lnConnHandle) SELECT (lnOrigArea) && restore original area RETURN NewIdTemp.nNewNumberThis is now very fast, but when I test the function in a tight loop to add 10000 new ids, SQL gives-up after about 4000 additions, with the error message...