Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Capture return value from a SQL statement

New Here ,
Mar 03, 2011 Mar 03, 2011

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

583
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 03, 2011 Mar 03, 2011

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 />

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Mar 03, 2011 Mar 03, 2011

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 03, 2011 Mar 03, 2011
LATEST

I just cracked it before looking at your reply.. But thanks very much for the quick response. Appreciate it.

Anil

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources