Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Crosstabular Query
Message
De
31/03/2001 05:47:34
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
30/03/2001 15:19:17
Steven Dyke
Safran Seats USA
Texas, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00490433
Message ID:
00490562
Vues:
8
>I have a cursor that lists customers and milestone dates for 24 different tasks.
>I want to create a query that makes the tasks the column headers and compliles the dates under this column in a spread sheet format for reporting purposes. I have created some crosstab queries before but of course they calculated values for the cells. This current one is a little differnt. Please Help.

Steven,
You could replace the dates with a diffence from a specific date to make them numeric and set back to date using same specific date. ie:
select customer, task, date()-duedate as duedate ;
from myTable ;
into cursor myCursor
*Crosstab 
*Extra overhead to convert nums to dates
An alternative is to build your own crosstabber. ie:
* Test file creation
Create cursor crosstabme (customer c(15), task c(15), duedate d)
Rand(-1)
For ix=1 to 10
  For jx=1 to 24
    If int(rand()*1000)%2=1
      Insert into crosstabme ;
        values ('Customer No '+padl(ix,3,'0'), ;
        'Task No '+padl(jx,3,'0'), ;
        date()+int(rand()*100))
    Endif
  Endfor
Endfor
Index on customer+task tag main
* Test file creation



External array arrRows, arrCols
* Cols array
Select distinct task from crosstabme ;
  order by task ;
  into array arrCols

lnFields = alen(arrCols,1)+1
Dimension arrCrossTabStruc[lnFields,4]
For ix=1 to lnFields
  arrCrossTabStruc[ix,1] = 'Task'+padl(ix-1,3,'0') && Fieldnames Task001,Task002...
  arrCrossTabStruc[ix,2] = 'C'
  arrCrossTabStruc[ix,3] = max(fsize('Task','crosstabme'),10) 
     && 10 is transform(date()) with century size
  arrCrossTabStruc[ix,4] = 0
Endfor
arrCrossTabStruc[1,1] = 'Customer'
arrCrossTabStruc[1,3] = fsize('Customer','crosstabme')

* Rows array
Select distinct customer from crosstabme ;
  into array arrRows ;
  order by 1

Create cursor crsTabbed from array arrCrossTabStruc
Dimension arrFirstRow[lnFields]
arrFirstRow[1]=''
Acopy(arrCols,arrFirstRow,1,-1,2)
Insert into crsTabbed from array arrFirstRow
For ix=1 to alen(arrRows,1) && For each customer
  Scatter memvar blank && create blank memvars for this customer
  m.customer = arrRows[ix] && Customer name
  For jx=1 to alen(arrCols,1) && For each task
    If seek(arrRows[ix]+arrCols[jx],'CrossTabMe','Main')
      Store transform(crosstabme.duedate) to ('m.Task'+padl(jx,3,'0'))
    Endif
  Endfor
  Insert into crsTabbed from memvar
Endfor
Browse
This one is easy to get rid of first row (long field name header as is) and converting char dates to datetype is a snap if desired.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform