Skip to main content
Known Participant
September 16, 2015
Answered

The value returned from the function is not of type query

  • September 16, 2015
  • 1 reply
  • 1356 views

I couldn't figure out why I got this error.  I have set default var query.  Please help.  If qLocal has records then return fine, but when qLocal records is empty will throw errors.  I've set a default.

<cffunction name="getName" access="public" returnType="query" output="false"
hint="This method returns a query.">
  <cfargument name="id_fk" required="no" default="0">
   <cfargument name="id2_fk" required="no" default="0">
 
  <cfset var qQuery = "">
   
   <cfquery name="qLocal" datasource="#db#">
         SELECT *
         FROM tbl
         WHERE id = <cfqueryPARAM value ="#id_fk#" CFSQLType ="CF_SQL_INTEGER"> AND id2 = <cfqueryPARAM value ="#id_fk2#" CFSQLType ="CF_SQL_INTEGER">
   </cfquery>


  <cfif qLocal.recordcount>
        <cfquery name="qQuery" datasource="db">                

          SELECT *

          FROM tbl2

          WHERE tbl2id = <cfqueryPARAM value ="#qLocal.id#" CFSQLType ="CF_SQL_INTEGER">

     </cfquery>

  </cfif>

  <cfreturn qQuery>
</cffunction>

    This topic has been closed for replies.
    Correct answer mkane1

    The query named qQuery only executes if the qLocal query returned records. You initialized qQuery as a variable, which is not a query object. If you initialize qQuery as a query object using QueryNew(columnlist) that should work.

    1 reply

    Legend
    September 16, 2015

    qQuery vs. qLocal.

    Known Participant
    September 16, 2015

    I think I understand but can you clarify?  Or maybe I have to create 2 functions for this?

    mkane1Correct answer
    Inspiring
    September 16, 2015

    The query named qQuery only executes if the qLocal query returned records. You initialized qQuery as a variable, which is not a query object. If you initialize qQuery as a query object using QueryNew(columnlist) that should work.