lnNumberToExtract = curPercentage.NumToFetch lnAreaCode = curPercentage.AreaCode lnTeam = curPercentage.Team ** Now use code from Sergey Berezniker (Al Doman) - may be not efficient, but quite elegant SELECT TOP lnNumberToExtract *, RECNO() AS rn, ; ROUND(RAND()*10000000000,0) AS ord ; FROM table1 ; WHERE AreaCode = m.lnAreaCode and Team = m.lnTeam ; ORDER BY ord ; INTO CURSOR crsRandto the following:
lnAreaCode = curPercentage.AreaCode lnTeam = curPercentage.Team lnNumberToExtract = curPercentage.NumToFetch if m.lnNumberToExtract<curPercentage.TeamCount ** Now use code from Sergey Berezniker (Al Doman) - may be not efficient, but quite elegant SELECT TOP lnNumberToExtract *, RECNO() AS rn, ; ROUND(RAND()*10000000000,0) AS ord ; FROM table1 ; WHERE AreaCode = m.lnAreaCode and Team = m.lnTeam ; ORDER BY ord ; INTO CURSOR crsRand else && we exceed original number of records, just select all records for that team select * from table1 WHERE AreaCode = m.lnAreaCode and Team = m.lnTeam into cursor crsRand NOFILTER endif