Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Jim Winter
  Where is Jim Winter?
 Williston
 Vermont - United States
 Jim Winter
 To: Godzilla Mozilla
  Where is Godzilla Mozilla?
 Kaduna
 Nigeria
 Godzilla Mozilla
 Tags
Subject: RE: Report Column Headers
Thread ID: 104289 Message ID: 104435 # Views: 1 # Ratings: 0
Version: Visual FoxPro 8 Category: Reports and Printers
Date: Wednesday, August 16, 2006 2:22:56 PM         
   


> Here is the description of my table
>
> Year Month Values
> 1951 January 319
> 1951 February 898
> 1951 March 765
> 1951 April 654
> 1951 May 343
> 1951 June 768
> 1951 July 900
> 1951 August 766
> 1951 September 765
> 1951 October 898
> 1951 November 876
> 1951 December 321
> 1952 January 319
> 1952 February 898
> 1952 March 765
> 1952 April 654
> 1952 May 343
> 1952 June 768
> 1952 July 900
> 1952 August 766
> 1952 September 765
> 1952 October 898
> 1952 November 876
> 1952 December 321
> 1953 January 319
> 1953 February 898
> 1953 March 765
> 1953 April 654
> 1953 May 343
> 1953 June 768
> 1953 July 900
> 1953 August 766
> 1953 September 765
> 1953 October 898
> 1953 November 876
> 1953 December 321
> .
> .
> .
> .
> .
>
> Another layout of the table is that, Month is the first column and the Year column the second.
>
> The number of clumns is not known in advance, as the years would determine that.
>
> Godzilla
>
>
> > > Dear Experts,
> > >
> > > I need to display a report based on the outcome of cross tabbing a table, my problem here is that, how can I generate the Column headers for the report since I don't know them in advance?
> > >
> > > Godzilla

> >
> >
> >
> > One way is you can use a "Field" object instead of a "Label" object for your headers.Then just enter the expression in each one:
> >
> > FIELD(1) FIELD(2) FIELD(3) etc.
> >
> > When run the expression will be evaluated and whatever you have as field names will appear in the "Field" object.


OK, I assume from your description that you want to get totals by year for your report. As you don't know how many years you will be reporting on, you can use Bernard's idea and create a bunch of reports all the same except for the number of columns. Name them each Year + the number of columns and then run something like the following, substituting your table name for Sample.
SELECT distinct Year FROM Sample INTO ARRAY aYears

nYears = _tally 

IF nYears > 0

  cSql = "SELECT"
  
  FOR i = 1 TO nYears
     cSql = cSql + IIF(i > 1, ', ',' ') + ;
                   'SUM(IIF(Year = "' + aYears[i] + '", Values, 000000000))' + ;
                   ' as Year' + aYears[i]
   ENDFOR 
   
   cSql = cSql + ' FROM Sample INTO TABLE xTab'
   
   &cSql
   
ENDIF                     

cReport = 'Year" + TRANSFORM(nYears)
REPORT FORM (cReport) TO PRINTER  


Regards,
Jim

ENTIRE THREAD

Report Column Headers Posted by Godzilla Mozilla @ 8/14/2006 5:41:17 PM
RE: Report Column Headers Posted by Jim Winter @ 8/14/2006 6:15:26 PM
RE: Report Column Headers Posted by Bernard Bout @ 8/15/2006 7:56:52 AM
RE: Report Column Headers Posted by Godzilla Mozilla @ 8/16/2006 12:31:08 PM
RE: Report Column Headers Posted by Jim Winter @ 8/16/2006 2:22:56 PM
RE: Report Column Headers Posted by Bernard Bout @ 8/17/2006 7:08:43 AM
RE: Report Column Headers Posted by Godzilla Mozilla @ 8/18/2006 7:06:26 PM