Search code examples
countfoxprovisual-foxpro

How to set variable query count result in visual foxpro 7


I am new in Visual FoxPro. I want to count rows by some id and print it in the report. Where I should place this query and how to set it to variable?


Solution

  • If you want it at the top of the report, before it has iterated through all the data, you need to pre-calculate it.

    select mytable
    sum myvalue for id="ABC" to gnTotal
    report form myreport to printer preview
    

    In this scenario gnTotal will be visible to the report and you can just use it in a report expression.

    If you want it in the summary band or you want subtotals by group you would use a report variable of type 'sum'. The expression for the variable would then be:

    iif(id="ABC", mytable.myvalue, 0)
    

    In other words if for a particular record the value of id is "ABC" then add myvalue to the sum, otherwise add zero.

    Then use the report variable in an expression at the bottom of the report.