> I am looking for an easy way to "SUM" 120 fields in a SELECT statement.

>

> The cursor (Qa) that I wish to "SUM" looks like:

>

> Qa.NUMBER, Qa.WK001, Qa.WK002, Qa.WK003, ........ Qa.WK120

>

> I would like to sort and group this cursor by "NUMBER" into another cursor, but I don't want to repeat the "sum" 120 times.

>

> Example

> SUM(Qa.WK001) as "Wk001", SUM(Qa.WK002) as "Wk002", ...SUM(Qa.WK0120) as "Wk120"

>

> Is there some quick way to sort these fields since they all begin with "WK" and are sequenced with "001" through "120"

>

> Thanks in advance,

>

> Paul D'Anna

There is "total" command. If you want SQL sum() then you need to list the sum(fieldName) in command. There is no way w/o a sum(...) in SQL it would sum those (you may write those sum() automated but at the end those sum(...) needs to be written). ie:

local ix, lcFields
lcFields = 'number'
for ix=1 to 120
lcFields = m.lcFields + textmerge(',sum(qa.WK<< padl(m.ix,3,"0") >>)')
endfor
select &lcFields from myTable qa group by 1

Cetin Basoz