>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.nNewNumber >>
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 SET LOCK_TIMEOUT 5000 UPDATE UniqueId SET @newId= nLastNumber = nLastNumber+1 WHERE UPPER(cFieldName) ='<<lcFieldName>>' SELECT @newId AS nNewNumber ENDTEXT PRIVATE nNewNumber IF SQLEXEC(lnConnHandle,lcSQLCmd,'NewIdTemp')=1 nNewNumber = nNewNumber USE ELSE nNewNumber = -1 ENDIF =SQLDISCONNECT(lnConnHandle) SELECT (lnOrigArea) && restore original area RETURN m.nNewNumber