CFLib.org – Common Function Library Project

queryAddColumnWithValue(query, column_name[, value])

Last updated December 13, 2005

author

Gabriele Bernuzzi

Version: 3 | Requires: CF6 | Library: DataManipulationLib

Description:
Adds a column filled with a value to a query object.

Return Values:
Returns a boolean.

Example:

<cfset foo = queryNew("name")>
<cfloop index="x" from="1" to="10">
    <cfset queryAddRow(foo)>
    <cfset querySetCell(foo, "name", "Name #x#")>
</cfloop>

<cfset queryAddColumnWithValue(foo, "age", "20")>

<cfdump var="#foo#">

Parameters:

Name Description Required
query Query to manipulate. Yes
column_name Name of new column. Yes
value Value to use. Defaults to nothing. No

Full UDF Source:

<!---
 Adds a column filled with a value to a query object.
 V2 by Raymond Camden
 v3 by author
 
 @param query      Query to manipulate. (Required)
 @param column_name      Name of new column. (Required)
 @param value      Value to use. Defaults to nothing. (Optional)
 @return Returns a boolean. 
 @author Gabriele Bernuzzi (gabriele.bernuzzi@gruppotesi.com) 
 @version 3, December 13, 2005 
--->
<cffunction name="queryAddColumnWithValue" returntype="boolean" output="false">
    <cfargument name="query" type="query" required="true" />
    <cfargument name="column_name" type="string" required="true" />
    <cfargument name="value" type="string" required="false" default="" />
    <cfset var arr=arrayNew(1) />
    
    <cfscript>
        arraySet(arr,1,arguments.query.recordCount,arguments.value);
        queryAddColumn(arguments.query, arguments.column_name, arr);
    </cfscript>

    <cfreturn true>
</cffunction>

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson