Skip to main content
Participant
September 10, 2009
Answered

How to Add extra data in result set of cfquerry?

  • September 10, 2009
  • 3 replies
  • 1191 views

hi all,

I am new to cold fusion please help me

i am using the cfquery tag for executing a select query and getting the system name and system is from that........

But i want an extra system name and system id to add to the result of that query with out changing the data base ..............

please any one suggest me ...........IT's URGENT

Thanks in advance
Sudheer

    This topic has been closed for replies.
    Correct answer Adam Cameron.

    Um... does that represent a row or two columns?

    Either way, there are functions to achieve either: queryAddRow() or queryAddColumn().  Have a look @ the query functions:

    http://livedocs.adobe.com/coldfusion/8/htmldocs/functions-pt0_16.html#1099653

    --

    Adam

    3 replies

    Participant
    September 10, 2009

    hey iam getting error when i use the QuerySetCell to add new row to it ...........

    Inspiring
    September 10, 2009

    sudheer keshetty wrote:

    hey iam getting error when i use the QuerySetCell to add new row to it ...........

    OK.

    Any chance of you letting us know what the error is and showing us the code that's erroring?

    --

    Adam

    BKBK
    Community Expert
    Community Expert
    September 10, 2009

    You'll have to use an array and the function queryAddColumn. An example follows.

    Suppose I have a result set called myQuery. There are 5 rows in it. I wish to add 2 new columns to the query, on the fly. The column names are username(type varchar) and userID(type integer)

    <!--- Create array corresponding to column username--->
    <cfset usernameArray = ArrayNew(1)>
    <cfset usernameArray[1] = "angelo@myDomain.com">
    <cfset usernameArray[2] = "bkbk@myDomain.com">
    <cfset usernameArray[3] = "carla@myDomain.com">
    <cfset usernameArray[4] = "chris@myDomain.com">
    <cfset usernameArray[5] = "mike@myDomain.com">

    <!---
    The next line adds the new column, username, to the query. That's it. Done.

    The array indices correspond to the row numbers in the query.
    The function queryAddColumn returns the column number for the newly added column
    (in case you'll need it, which you usually wont ).
    --->
    <cfset columnNumber = queryAddColumn(myQuery, "username", "VarChar", usernameArray)>

    <!--- Now, do the same for the next new column, userID  --->
    <cfset userIDArray = ArrayNew(1)>
    <cfset userIDArray[1] = "23">
    <cfset userIDArray[2] = "121">
    <cfset userIDArray[3] = "9">
    <cfset userIDArray[4] = "76">
    <cfset userIDArray[5] = "44">

    <cfset columnNumber = queryAddColumn(myQuery, "userID", "integer", userIDArray)>

    Participant
    September 10, 2009

    Thanks a lot I got it

    Adam Cameron.Correct answer
    Inspiring
    September 10, 2009

    Um... does that represent a row or two columns?

    Either way, there are functions to achieve either: queryAddRow() or queryAddColumn().  Have a look @ the query functions:

    http://livedocs.adobe.com/coldfusion/8/htmldocs/functions-pt0_16.html#1099653

    --

    Adam