I'm struggling with understanding the right syntax...
# cfml-beginners
s
I'm struggling with understanding the right syntax for what I need to do so hopefully one of you fine people on this channel can enlighten me. I'm creating a query object that contains a set of prices, populated from a database query. This part works fine.
<cfset maxpriceQuery = QueryNew("id,maxprice","integer,integer")>
<cfset QueryAddRow(maxpriceQuery, #get.recordcount#)>
<cfset intMaxPriceLoop = 1>
<cfloop query="get">
<cfset QuerySetCell(maxpriceQuery, "id", #id#, intMaxPriceLoop)>
<cfset QuerySetCell(maxpriceQuery, "maxprice", #maxprice#, intMaxPriceLoop)>
<cfset intMaxPriceLoop = intMaxPriceLoop + 1>
</cfloop>
Then I want to be able to select from that query, something like this...
select top 2 id from maxpriceQuery where maxprice <= #getprice.price#
But I don't know how. Can someone help? I thought maybe I could use this...
<cfquery name="getmydata" datasource="maxpriceQuery">
...but that's evidently wrong because maxpriceQuery is not a valid datasource. I'm sure I did this once years ago but I'll be darned if I can figure out how. :-)
m
<cfquery name="getmydata" dbtype="query">
then do your select from the query name as though it is a table.
For more attributes if you need them.
👍 1
s
@Mark Takata (Adobe) Thank you so much. Honestly, I could have sworn I had tried that already but I must have got it wrong somehow. I very much appreciate your helpful and very quick reply. Exactly what I needed.
❤️ 1
m
My pleasure, happy to help!
a
Are you doing anything else with that
maxpriceQuery
query though - that's a long way around to get the top 2 items. I would think a
queryFilter
on the original
get
query would be a much cleaner way to handle that (assuming
maxpriceQuery
isn't used anywhere else)