4

Is it possible to sort a query object by the length of a varchar column using Query of Queries in ColdFusion?

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
Henry
  • 32,689
  • 19
  • 120
  • 221

2 Answers2

5

There is no way to do this entirely with QoQ, no: the QoQ implementation does not provide a len() function. Instead, you could get the database to provide the length data for you.

In the original query add:

len(fieldYouNed) as fieldYouNedLen

In the QoQ then use:

SELECT * FROM query ORDER BY fieldYouNedLen
Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
Paul
  • 1,577
  • 7
  • 10
2

In Coldfusion 10, you could use the sortBy() function of the Underscore.cfc library like so:

sortedQuery = _.sortBy(queryObject, function(row) {
   return len(row.column);
});

(Disclaimer: I created this library)

Russ
  • 1,931
  • 1
  • 14
  • 15