Copy link to clipboard
Copied
Hello all,
I would like to capture and display the return value of an SQL statement. Below given is the code:
<cfcomponent>
<cffunction name="addship" access="remote">
<cfquery name="shippers" datasource="northwindodbc" result="maxshipperid">
select max(shipperid) from shippers
</cfquery>
</cffunction>
</cfcomponent>
The above given SQL statement is returning the max shipperid which in this example has to be 3. How do I capture this return value on an external variable which can be accessed outside the cfquery statement.
Any quick response is highly appreciated.
Anil
Copy link to clipboard
Copied
The result of your query is in the variable called "shipper". It is the same as the name of your query. You can also return that from your function.
<cfreturn shipper />
Copy link to clipboard
Copied
You need to include the "AS xxx" in the query so that you have a name to reference it as outside of the query:
<cfquery name="shippers" datasource="northwindodbc" result="maxshipperid">
select max(shipperid) AS maxShpperID from shippers
</cfquery>
Max Id is #shippers.maxShipperID#
-reed
Copy link to clipboard
Copied
I just cracked it before looking at your reply.. But thanks very much for the quick response. Appreciate it.
Anil