>I use SUBSTR(SYS(2015),3,10) as a unique id all through my system. I started this because I understood it is based on the present time which to me seems to be always unique.
>
>Now I am considering using integers because I heard that SEEKing and ORDERing is quicker with them.
>
>Is there an equivalent expression that results in a unique integer?
The first function can run into trouble. What happens if two people hit at exactly the same time? Or in fall fall when Standard Time begins and you set the clocks back an hour and the people working the graveyard shift have the 1:00 am hour twice?
I use a table to store the next ID, then increment it:
LPARAMETER tcTable
LOCAL lnArea, lnRetVal
lnArea = SELECT()
IF !USED("Keys")
USE Keys IN 0
ENDIF
SELECT Keys
LOCATE FOR UPPER(Table( = UPPER(tcTable)
DO WHILE !FLOCK()
ENDDO
lnRetVal = NextKey
REPLACE NextKey WITH NextKey + 1
UNLOCK
SELECT (lnArea)
RETURN lnRetVal
Craig
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer