<CF_QueryTranspose>

Takes a query and transposes ("pivots") the columns and rows. Requires the CF_ArrayToQuery, CF_QueryToArray, and CFX_QueryColumns custom tags (all available from either Allaire's Tag Gallery or Nate's list of custom tags).

Parameters
QUERY Required. The query that you want to transpose. Could be the result of a CFQUERY or any other CF tag that generates a query result set.
NEWQUERY Optional. A name for the new, transposed version of the query. If ommitted, the original query is overwritten (replaced) with the new, transposed version.
ADDLABELSFROM Optional. One of the columns from the original query.

If ADDLABELSFROM is provided, then values from each row of the original query will be used to create column names for the new query. The column names will consist of the column you provide here, then an underscore, then the value of each row from the corresponing column in the original query (see example 2). Default is No.

NOTE: If you use this option, it is your responsibility to ensure that the resulting column names will be "legal" variable names to CF. Meaning that the values in the original query for the column you specify for ADDLABELSFROM must contain only numbers, letters, or underscores.

ADDCOLUMNNAMES Optional. Yes or No. If ADDCOLUMNNAMES="Yes", then the column names from the original query will be added to the first column of each row of the new query (see example 3). If ADDCOLUMNNAMES="No" or is ommitted, then the columns of the new query will just be named Col1, Col2, Col3, and so on.
TOPLEFTLABEL Optional. If ADDCOLUMNNAMES="Yes", then you may provide text here that will become the column name for the first column of the new query (the column that has the original column names for its rows). If ommitted, the default label of "Columns" will be used.

Examples
For the following examples, assume that the following CFQUERY tag has been executed:

<CFQUERY NAME="GetData" DATASOURCE="A2Z"> SELECT * FROM Customers </CFQUERY>
CUSTOMERID COMPANY FIRSTNAME MIDDLEINIT LASTNAME ADDRESS1 ADDRESS2 CITY STATE ZIP PHONE EMAIL CUSTOMERSINCE
1ABC CompanyArnoldBCooper123 West 1st Street1st FloorAnywhereNY00001212 555 1212acooper@abc.com1996-07-16 00:00:00
2DEF CompanyDianaEFontaine456 East 2nd StreetSuite 1200AnyplaceNY00002718 555 1212dfontaine@def.com1995-05-05 00:00:00
Example 1
<CF_QueryTranspose QUERY="GetData">
COL1 COL2
12
ABC CompanyDEF Company
ArnoldDiana
BE
CooperFontaine
123 West 1st Street456 East 2nd Street
1st FloorSuite 1200
AnywhereAnyplace
NYNY
0000100002
212 555 1212718 555 1212
acooper@abc.comdfontaine@def.com
1996-07-16 00:00:001995-05-05 00:00:00

Example 2

<CF_QueryTranspose QUERY="GetData" ADDLABELSFROM="CustomerID">
CUSTOMERID_1 CUSTOMERID_2
12
ABC CompanyDEF Company
ArnoldDiana
BE
CooperFontaine
123 West 1st Street456 East 2nd Street
1st FloorSuite 1200
AnywhereAnyplace
NYNY
0000100002
212 555 1212718 555 1212
acooper@abc.comdfontaine@def.com
1996-07-16 00:00:001995-05-05 00:00:00

Example 3

<CF_QueryTranspose QUERY="GetData" ADDLABELSFROM="CustomerID" ADDCOLUMNNAMES="Yes" TOPLEFTLABEL="Data">
DATA CUSTOMERID_1 CUSTOMERID_2
CUSTOMERID12
COMPANYABC CompanyDEF Company
FIRSTNAMEArnoldDiana
MIDDLEINITBE
LASTNAMECooperFontaine
ADDRESS1123 West 1st Street456 East 2nd Street
ADDRESS21st FloorSuite 1200
CITYAnywhereAnyplace
STATENYNY
ZIP0000100002
PHONE212 555 1212718 555 1212
EMAILacooper@abc.comdfontaine@def.com
CUSTOMERSINCE1996-07-16 00:00:001995-05-05 00:00:00