CFFEED, don’t forget you can cast() the resulting query column

It’s probably old news to folks who have been using Query of Query a lot but now with CFFEED, some developers may be using the query of query feature for the first time.

CFFEED when converting to a query has no knowledge of data type for any given column. In the example below, google’s news feed returns a column (PUBLISHEDDATE) that is treated as a string but is in fact a date. Thus when you try to sort by PUBLISHEDDATE, it doesn’t work the way you would expect. By using the cast() function, I’m able to on the fly sort the query as a date.


<!--- set feed --->
<cfset feed = "http://news.google.com/?output=rss">
<!--- grab feed --->
<cffeed action="read" source="#feed#" query="rss" userAgent="Mozilla/4.0" properties="rssProperties">
<!---  Sort query by date after casting it as a date --->
<cfquery dbtype="query" name="rss">
SELECT
Title, CAST(PUBLISHEDDATE as date) as publisheddate, rsslink, content
FROM
RSS
ORDER BY
publisheddate desc
</cfquery>
Posted in ColdFusion, QoQ.

2 Responses to “CFFEED, don’t forget you can cast() the resulting query column”

  1. Gary F Says:

    That’s clever. I didn’t realise anything beyond basic sql was possible. I found the page in the CF manual in case others want to know what other datatypes they can convert like that. http://livedocs.adobe.com/coldfusion/8/htmldocs/using_recordsets_8.html

  2. Vincent Collins Says:

    I can’t tell you how many times I wrote something complicated in CF where a simple SQL Statement would have taken care of it.

Leave a Reply