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>
Vince Collins
February 22, 2008 at 3:06 pm
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
February 24, 2008 at 8:48 am
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.