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.
The number of the column that was added.
QueryAddColumn(query, columnName [, columnType], array)
QueryNew, QueryAddRow, QuerySetCell; Managing data types for columns in Query of Queries user guide in the Developing ColdFusion Applications
ColdFusion (2018 release): Introduced named parameters.
ColdFusion MX 7: Added the datatype parameter.
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.)
Parameter |
Description |
|---|---|
query |
Name of a query object. |
columnName |
Name of the new column. |
columnType |
(Optional) Column data type. ColdFusion generates an error if data you add to the column is not of this type, or if it cannot convert the data to this type. The following data types are valid:
|
array |
Name of an array whose elements populate the new column. |
You can add columns to query objects, such as queries retrieved with the cfquery tag or queries created with the QueryNew function. You cannot use the QueryAddColumn function on a cached query. This function is useful for generating a query object from the arrays of output parameters that Oracle stored procedures can generate .Adobe recommends that you use the optional datatype parameter. Without this parameter, ColdFusion must try to determine the column's data type when it uses the query object in a query of queries. Determining the data type requires additional processing, and can result in errors if ColdFusion does not guess the type correctly.
<cfscript>
myQuery=QueryNew("Country,Capital","varchar,varchar");
/*Add array values in column*/
myColumnValues=ArrayNew(1);
myColumnValues[1]=320;
myColumnValues[2]=250;
myColumnValues[3]=200;
QueryAddColumn(myQuery,"Population_millions","varchar",myColumnValues);// Add column Population_millions
WriteDump(myQuery);
</cfscript>
Output
<cfscript>
myQuery=QueryNew("Country,Capital","varchar,varchar");
/*Add array values in column*/
myAreaValues=ArrayNew(1);
myAreaValues[1]=100000;
myAreaValues[2]=50000;
myQuery.addColumn("Area","integer",myAreaValues);
WriteDump(myQuery);
</cfscript>
Sign in to your account