Access a specific resultset (Query) row

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Access a specific resultset (Query) row

    I am iterating over a CF Query and want to implement a generic function which
    takes the query and the rownumber as a parameter. How can I access a specific
    row in a CF Query Object and retrieve the complete row as struct?

    Are there any functions on CF Query objects which I can access.

    A requirement is that I do not change the cursor (CurrentRow) while iterating
    over the query and retrieving the data.

    vernade Guest

  2. Similar Questions and Discussions

    1. #6503 [Asn->Opn]: no support for multiple resultset query?
      ID: 6503 Updated by: tony2001@php.net Reported By: alonso at computacionlegal dot com -Status: Assigned +Status: Open Bug...
    2. #6503 [Opn->Asn]: no support for multiple resultset query?
      ID: 6503 Updated by: bjori@php.net Reported By: alonso at computacionlegal dot com -Status: Open +Status: Assigned Bug Type:...
    3. return query resultset from custom tag
      Hi, How to return an entire query resultset from custom tag to the calling page ? Thanks for your help. vmrao
    4. Getting recordcount from resultset of 'union' query
      Hi, I need to find out the number of records in the resultset of a union of 2 queries. E.g. "select ID from Pages where numPageCatID = " &...
    5. web services problem processing embedded query resultset
      We ran into an interesting problem with using queries and web services. This was on MX 6.1 Windows. This may be known already, though we didn't find...
  3. #2

    Default Re: Access a specific resultset (Query) row

    As far as I know there are no CF functions that return an entire query row as a
    structure, but you can create your own function. Just pass in a query object
    and a row number and the function uses the query.columnList to add the column
    values for the current row to the returned structure.



    <!--- return selected query row as a structure --->
    <cfscript>
    function GetQueryRow(query, rowNumber) {
    var i = 0;
    var rowData = StructNew();
    var cols = ListToArray(query.columnList);
    for (i = 1; i lte ArrayLen(cols); i = i + 1) {
    rowData[cols[i]] = query[cols[i]][rowNumber];
    }
    return rowData;
    }
    </cfscript>

    <cfoutput query="yourQuery">
    <cfset theCurrentRow = GetQueryRow(yourQuery, currentRow)>
    <cfdump var="#theCurrentRow#">
    </cfoutput>

    mxstu Guest

  4. #3

    Default Re: Access a specific resultset (Query) row

    Thank you for your response... this was exactly the solution I was looking for.
    I did not realize that you can access a query object with brackets, like
    query[column][row].

    The CF documentation either misses this point or I was not able to find it.


    vernade Guest

  5. #4

    Default Re: Access a specific resultset (Query) row

    You can use a query of a query to do this too:

    <cfquery name="myQueryRow" dbtype="query">
    SELECT * FROM myOtherQuery WHERE id=id_of_row
    </cfquery>

    Then myQueryRow will only have the row you're selecting, as a query object of its own.
    Rachel Guest

  6. #5

    Default Re: Access a specific resultset (Query) row

    I tried several approaches, none of them worked for me except this one:

    queryName.field_name[rowNumber]

    Can use the queryName.currentrow property to get the current row number and then just add one to it to get your rowNumber
    Matt Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139