troubleshooting Question

In ColdFusion, how to access results of a query

Avatar of bassman592
bassman592Flag for United States of America asked on
ColdFusion Language
6 Comments1 Solution12 ViewsLast Modified:
Using ColdFusion, I have a .cfc file that contains a cfquery the creates and executes a SQL SELECT statement:

<cffunction name="get_data" returntype="query">
    <cfset var local = StructNew()>
...
<cfquery name="local.my_data" datasource="datasource">
...
[in here is a rather lengthy SELECT statement]
...
</cfquery>


 <cfreturn( local.my_data )>


</cffunction><!--- get_data() --->

In a separate function (in the same .cfc file) , I have code that creates a spreadsheet and then allows the user to download that spreadsheet. That part works fine (I tested it using sample data). Now however, I need to populate the newly-created spreadsheet (spreadsheetObj) with the results of the aforementioned query. It appears that actually populating the spreadsheet is pretty trivial:

<!--- Add data from query --->
<cfset SpreadsheetAddRows(spreadsheetObj, [query object])>

however, I am having trouble specifying the query object as the second parameter. I have tried using "my_data", "get_data.my_data", and just "get_data". In each case, I received an error. Sometimes the error is "Element MY_DATA is undefined in GET_DATA." and sometimes it is "The value specified for the second parameter is not a valid query or a one-dimensional or two-dimensional array.".

Is it possible for me to use this query result in a separate function?







Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros