Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How do I represent three-dimensions on a form? CrossTAB?
Message
De
14/09/2000 13:52:18
J Chris Powell
Myers and Stauffer Lc
Kansas, États-Unis
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00416181
Message ID:
00416523
Vues:
30
This function simulates the pivot table. I just wrote it and briefly tested it. If you find that I have missed something, please email it to me. I would like to perfect it. I have used this technique extensively, but have never abstracted it out to a function like this. It has some limitations, but can be a pretty handy tool.
*: Pivot.prg
*: J Chris Powell, 2000
*: Please report any bugs to jchris@kscable.com
*: Pass the alias of the table you are wanting to summarize
*:		The field that you want summarized
*:		The criteria that will define the columns in the new cursor
*:		And the criteria that will define the rows (Optional, if only one row is desired)
*: Example:
*		PIVOT("Sales", "Amount", "SalesPerson")
*			Creates a cursor with a column for every salesperson with the total sales
*		PIVOT("Sales", "Amount", "Month", "SalesPerson")
*			Creates a cursor with a row for every salesperson and a column for every month.
*: Returns the number of records generated

LPARAMETER Alias, field, column, row
LOCAL SQL, FieldToGet
SQL = ''
FieldToGet = m.Alias + '.' + m.Column
SELECT &FieldToGet. as Column ;
	FROM (Alias) ;
	GROUP BY &Column. ;
	INTO CURSOR HoldPivot

IF _Tally > 0
	SCAN
		SQL = m.SQL + IIF(EMPTY(m.SQL),'',',') + "SUM(IIF(" + m.Column + ' = "' + ALLTRIM(HoldPivot.Column) + '", ' + m.Field + ', 0)) AS ' + ALLTRIM(HoldPivot.Column)
	ENDSCAN

	SQL = 'SELECT ' + IIF(EMPTY(m.Row),'',m.Row + ', ') +  m.SQL
	SQL = m.SQL + ' FROM ' + m.Alias

	IF NOT EMPTY(m.row)
		SQL = m.SQL + ' GROUP BY ' + m.row
	ENDIF
	&SQL.
ENDIF
USE IN HoldPivot
RETURN _Tally
Hope that helps
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform