User Guide
642 Chapter 3: ColdFusion Functions
QueryAddColumn
Description
Adds a column to a query and populates its rows with the contents of a one-dimensional array.
Pads query columns, if necessary, to ensure that all columns have the same number of rows.
Returns
The number of the column that was added.
Category
Query functions
Function syntax
QueryAddColumn(query, column-name, array-name)
See also
QueryNew, QueryAddRow, QuerySetCell
History
ColdFusion MX: Changed behavior: if a user attempts to add a column whose name is invalid,
ColdFusion throws an error. (In earlier releases, ColdFusion permitted the add operation, but the
user could not reference the column after adding it.)
Parameters
Usage
You can add columns to query objects such as queries retrieved with the cfquery tag or queries
created with the
QueryNew function. You cannot us the QueryAddColumn function on a cached
query.
Useful for generating a query object from the arrays of output parameters that Oracle stored
procedures can generate.
Example
<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 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">
Parameter Description
query Name of a query that was created with
QueryNew.
column-name Name of the new column.
array-name Name of an array whose elements are to populate the new column.