This looks like you're trying to generate the next primary key. MAX(primary_key) is one of the slowest ways to do it.
http://fox.wikis.com/wc.dll?Wiki~MkKey>In vfp 8 i would get the max integer key value in a table with:
>
>local lavalue[1]
>lavalue = .f.
>select max(fkey) from table into array lavalue
>
>lavalue[1] would return .f.
>
>in Vfp 9 sp1 this returns .NULL.
>
>I can change the select statement to
>select max(fkey) from table group by fkey into array lavalue
>
>and lavalue[1] will return .f.
>
>
>Code to test this
>
>create cursor ken (fkey I)
>local lavalue[1]
>
>lavalue = .f.
>select max(fkey) from ken into array lavalue
>? lavalue[1]
>
>I don't remember having this problem in Vfp 9
>has any one else had this problem?
>
>Ken