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?
Our community of experts have been thoroughly vetted for their expertise and industry experience.