#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    60
    Rep Power
    4

    get value of query object using conctenation


    Hi guys ,

    Iam trying to make the following statment more generic but it gives me "String values instead the real value" my code is below :

    <cfset i = 7/>
    cfset col1 = "qSheetData." & "column" & #i#/>
    <cflop query="qSheetData">
    <cfset strMonth = #col1#/>
    </cfloop>

    This gives me strMonth as string "qSheetData.column7" and not as a value.

    if i replace by <cfset strMonth = qSheetData.column7/> ,
    this will work..and give me my query data


    Can any body tells me how should i get the data using the 1st statment ?


    thanks
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2008
    Posts
    131
    Rep Power
    7
    cfset col1 = "qSheetData." & "column" & #i#
    As you have seen, that code just concatenates a bunch of strings to produce a bigger string. It does not evaluate anything other than the variable "i".

    To access a query column dynamically, you need to use array notation. Since you are looping through a query, you can use cfquery's currentRow variable as the rowNumber

    Code:
    <cfset value = queryName["columnName"& i][rowNumber]>
  4. #3
  5. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,265
    Rep Power
    968
    cfSearching is right. You're not using the structure syntax to build up the column reference.

IMN logo majestic logo threadwatch logo seochat tools logo