ldStartMonth = DATE(2007,04,01) && Starting date for report... April ldFromDate = ldStartMonth && default from date as that starting report */ Build a clause for each month you want the report to show column across.. lcSQLFields = "" FOR lnI = 1 TO 3 ldFromDate = ldStartMonth ldEndDate = GOMONTH( ldFromDate, 1 ) -1 && force to last day of the month lcSQLFields = lcSQLFields; + "'" + CMONTH( ldFromDate ) + "' as MonthHdr" + ALLTRIM( STR( lnI )) + ", "; + SUM( IIF( BETWEEN( sls.date, ldFromDate, ldEndDate ), 1, 0 ) * sls.Free )) "; + " as MonthFree" + ALLTRIM( STR( lnI )) + ", "; + SUM( IIF( BETWEEN( sls.date, ldFromDate, ldEndDate ), 1, 0 ) * sls.Amt )) "; + " as MonthAmt" + ALLTRIM( STR( lnI )) ; + IIF( lnI = 3, "", ", " ) && no trailing comma if on last loop ENDFOR select; sls.product,; &lcSQLFields ; FROM ; sales.dbf sls; GROUP BY ; sls.product; INTO ; CURSOR C_ReportResultsNow, your report can refer to the
>-------------------------------------------------------------------------------------- >|Product | April | May | June | >| |---------------------|---------------------|---------------------| >| | Qty | Free |Amount | Qty | Free |Amount | Qty | Free |Amount | >-------------------------------------------------------------------------------------- > >my dbf (sales.dbf) is like this : > >product c (30) >date d >qty n (10) >free n (10) >amt n(10,2) > > >>