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

Weird error in cfquery , cannot use cfelse in cfquery ?

Guest
May 11, 2011 May 11, 2011

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

625
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

correct answers 1 Correct answer

Advocate , May 11, 2011 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.

Translate
LEGEND ,
May 11, 2011 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

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
LEGEND ,
May 11, 2011 May 11, 2011

Did you pass two numeric arguments?

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
Guest
May 11, 2011 May 11, 2011

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

Just the error will pop up.

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 ,
May 11, 2011 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.

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
Guest
May 11, 2011 May 11, 2011
LATEST

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.

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