How do I sort a query object in ColdFusion 7?

Hooray Im Helping picture Hooray Im Helping · Jul 22, 2009 · Viewed 11.4k times · Source

I have a query object, with, say, fifteen rows returned. For all intents and purposes, I can't modify the SQL which generates the query object, but I need to sort this query object by column. Is there a way to do this in ColdFusion 7 without resorting to an external library?

Edit: I should add: I've run a query on this query object, and done an ORDER BY clause in this query of the query. Is there another way of doing this?

Answer

ale picture ale · Jul 22, 2009

No, a query of query is the way you would do this. There are other ways you could monkey around with the data, but they're all kludgey and wouldn't be as straightforward as QoQ.

One of the powers of QoQ (aka in-memory queries) is that it can be used on the query returned by any tag that returns a query object, for instance CFDIRECTORY and CFPOP.

For folks wondering how to do a Query of Query, it's simple:

<cfquery name="resortQuery" dbtype="query">
    SELECT *
    FROM myQueryFromSomewhereElse
    WHERE
        COLUMN_NAME=<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#myFilterValue#" />
    ORDER BY
        SOME_OTHER_COLUMN_NAME ASC
</cfquery>