Skip to main content
May 11, 2011
Answered

Weird error in cfquery , cannot use cfelse in cfquery ?

  • May 11, 2011
  • 3 replies
  • 694 views

<cfargument name="StateID" type="any"  default="">

<cfargument name="LocationID2" type="any"  default="">

<cfset var data ="">

<cfquery datasource="#ds#" name="data">

SELECT s.State_ID, s.State, l.Location_ID, l.Area, l.State_ID, r.Name, r.Location_ID

FROM State s, Location l, Restaurants r

WHERE 0=0

AND r.Location_ID = l.Location_ID

AND l.State_ID = s.State_ID

<cfif #ARGUMENTS.LocationID2# LT 9>

AND l.State_ID = (#ARGUMENTS.LocationID2#)

<cfelse>

AND l.Location_ID = (#ARGUMENTS.LocationID2#)

</cfif>

This is the code in component file, it is working with normal form with action.

But when i try to make it with ajax, something like <cfdiv bind="......." > , it get error with

58 :           AND l.St

ate_ID = (#ARGUMENTS.LocationID2#)
59 :           <cfelse>
60 :                AND l.Location_ID = (#ARGUMENTS.LocationID2#)
61 :           </cfif>

but when i take away the cfelse , it working without any error. I just feel weird , can some one please give me some tips ?

    This topic has been closed for replies.
    Correct answer Steve Sommers

    It's hard without the error message but just for kicks, try changing your if statement to the following:

    <cfif val(ARGUMENTS.LocationID2) LT 9>

    AND l.State_ID = #val(ARGUMENTS.LocationID2)#

    <cfelse>

    AND l.Location_ID = #val(ARGUMENTS.LocationID2)#

    </cfif>

    If this works then the function caller is not providing the LocationID2 argument and since your declaration does not require a value and defaults it to "", arguments.LocationID2 is not a number.

    3 replies

    Steve SommersCorrect answer
    Legend
    May 11, 2011

    It's hard without the error message but just for kicks, try changing your if statement to the following:

    <cfif val(ARGUMENTS.LocationID2) LT 9>

    AND l.State_ID = #val(ARGUMENTS.LocationID2)#

    <cfelse>

    AND l.Location_ID = #val(ARGUMENTS.LocationID2)#

    </cfif>

    If this works then the function caller is not providing the LocationID2 argument and since your declaration does not require a value and defaults it to "", arguments.LocationID2 is not a number.

    May 11, 2011

    Thank you ! ! !

    I follow the way you show me and solve my problem !

    Another way, if i change the argument type to "numeric" can be avoid this kind error?

    If i just need the result with numeric.

    Inspiring
    May 11, 2011

    Did you pass two numeric arguments?

    May 11, 2011

    Ya, i pass two numeric arguments after i continue click with it.

    Just the error will pop up.

    Inspiring
    May 11, 2011

    You say you get an error, but you don't say what the actual error message is.  All you've given us is the context of where the error is occurring.

    So it's difficult to say anything sensible about this.

    --

    Adam