QueryAddColumn

Adds a new column to a specified query and populates the column's rows with the contents of a one-dimensional array. Returns the query object with the additional column. Padding is added, if necessary, on the query columns to ensure that all columns have the same number of rows.

See also QueryNew, QueryAddRow and QuerySetCell.

Syntax

QueryAddColumn(query, column-name, array-name)
query

Name of a query that was created with QueryNew.

column-name

The name of the new column.

array-name

The name of the array whose elements are to populate the new column.

Usage

This function is particularly useful if you are an Oracle developer and would like to generate a query object from the arrays of output parameters which Oracle stored procedures can generate. Padding is added, if necessary, on the query columns to ensure that all columns have the same number of rows.

Example

<!--- This example shows the use of QueryAddColumn --->

<HTML>

<HEAD>
<TITLE>
QueryAddColumn Example
</TITLE>
</HEAD>

<BASEFONT FACE="Arial, Helvetica" SIZE=2>

<BODY  bgcolor="#FFFFD5">

<BODY>

<H3>QueryAddColumn Example</H3>

<P>This example adds three columns to a query object and then populates 
the columns with the contents of three arrays.</P>  

<P>After populating the query, the example shows, in tabular format, the
contents of the columns.</P> 

<!--- make a new query --->
<CFSET myQuery=QueryNew("")>

<!--- create an array --->
<CFSET FastFoodArray=ArrayNew(1)>
<CFSET FastFoodArray[1]="French Fries">
<CFSET FastFoodArray[2]="Hot Dogs">
<CFSET FastFoodArray[3]="Fried Clams">
<CFSET FastFoodArray[4]="Thick Shakes">

<!--- add a column to the query --->
<CFSET nColumnNumber=QueryAddColumn(myQuery, "FastFood", FastFoodArray)>

<!--- create a second array --->
<CFSET FineCuisineArray=ArrayNew(1)>
<CFSET FineCuisineArray[1]="Lobster">
<CFSET FineCuisineArray[2]="Flambe">

<!--- add a second column to the query --->
<CFSET nColumnNumber2=QueryAddColumn(myQuery, "FineCuisine", 
FineCuisineArray)>

<!--- create a third array --->
<CFSET HealthFoodArray=ArrayNew(1)>
<CFSET HealthFoodArray[1]="Bean Curd">
<CFSET HealthFoodArray[2]="Yogurt">
<CFSET HealthFoodArray[3]="Tofu">

<!--- add a third column to the query --->
<CFSET nColumnNumber3=QueryAddColumn(myQuery, "HealthFood", 
HealthFoodArray)>

<table cellspacing="2" cellpadding="2" border="0">
<tr>
    <th align="left">Fast Food</th>
    <th align="left">Fine Cuisine</th>
    <th align="left">Health Food</th>
</tr>
<CFOUTPUT query="myQuery">
<tr>
    <td>#FastFood#</td>
    <td>#FineCuisine#</td>
    <td>#HealthFood#</td>
</tr>
</CFOUTPUT>
</table>

<P><B>Note:</B> Because there are fewer elements in the Fine Cuisine and 
Health Food arrays, QueryAddColumn 
added padding to the corresponding columns in the query.</P>
 
</BODY>
</HTML>