Is it possible to sort a query object by the length of a varchar column using Query of Queries in ColdFusion?
Asked
Active
Viewed 933 times
2 Answers
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
-
I saw Russ just blogged it recently it's quite nice and looks nice. – Paul Jul 02 '12 at 03:41
-
Thanks, I hope to add Railo 4 support soon too – Russ Jul 02 '12 at 21:28