Select ceiling(year(EndDate) - year(StartDate)/5) as Period, count(*) as NumEmployees from curYears group by 1 order by 1 into curToProcess readwrite index on Period tag Period go bottom in curToProcess local lnMaxPeriod as Integer, lcCommand as String lnMaxPeriod = curToProcess.Period && Maximum number of periods ** Now do we want to create field for every periods, even if we don't have them? Let's assume yes. lcCommand = "create cursor curFinal (" for lnI =1 to m.lnMaxPeriod + 1 lcCommand = m.lcCommand + "var" + transform(m.lnI) + " I " + (iif(m.lnI <=m.lnMaxPeriod, ", ", ")") next execsript (m.lcCommand) && or &lcCommand - create the curFinal cursor append blank in curFinal scatter memvar for lnI =0 to m.lnMaxPeriod if seek(m.lnI, 'curToProcess') store curToProcess.NumEmployees to ("m.var" + transform(m.lnI +1)) endif next gather memvar ** Now we have our curFinal with one line of all number of employees per period of service.This is from the top of my head - not tested.