QueryAddColumn

Description

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

Category

Query functions

Syntax


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

See also

QueryNew, QueryAddRow, QuerySetCell

Parameters

Parameter
Description
query
Name of a query that was created with QueryNew.
column-name
The name of the new column.
array-name
The name of an array whose elements are to populate the new column.

Usage

You can add columns to any type of query object, such as queries retrieved with cfquery or queries created with QueryNew. The only type of query that you cannot use QueryAddColumn on is a cached query.

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>    



Banner.Novgorod.Ru