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 Solution15 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() --->

Open in new window


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])>

Open in new window


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?







ASKER CERTIFIED SOLUTION
erikTsomik
System Architect, CF programmer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 6 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 6 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004