Query Task Where Clause with Integers
I have a workflow for finding dentists near the user, but I also want it to be able to only select the dentists in the area that serve the age that the user entered. I created columns in the dentist feature class for the minimum and maximum ages served by each dentist (MinAge and MaxAge) and added a text box for the user to enter an age. I called the resulting string variable 'userAge'.
Because I need everything in the query where clause to be an integer, I cast 'userAge' into the Int32 variable 'userAgeInt'.
I then entered the following expression into the query:
"MinAge <= userAgeInt AND MaxAge >= userAgeInt"
It should work, but it doesn't. When I replace 'userAgeInt' with a random number, say 5, it works perfectly. However, as soon as I put the variable back in, it doesn't work anymore. I tried only using MinAge and ditching the second half of the expression, but it doesn't even work without the and.
I also added alerts that show both 'userAge' and 'userAgeInt.toString', and they both show the correct value.
Any ideas why this won't work?
0
-
Hi Denise,
Is "MinAge <= userAgeInt AND MaxAge >= userAgeInt" what you are having in the “where” argument of the QueryTask?
If that’s the case the query task expects that both “MaxAge” and “userAgeInt” are attributes of your map service and tries to compare those attributes. This also explains why if you hardcode values it works.
I think the syntax for your scenario should be
"MinAge <= “ & userAgeInt & “ AND MaxAge >= “ & userAgeInt
This is not limited to integer but as general rule. If your values were strings you might need to wrap values in single quotes but for your scenario it should be plain as above.
I hope this helps0 -
Francesca,
That did the trick! It works now! Thank you so much! I figured it was something like that, but I am very new to VB script. Thank you again!0
Please sign in to leave a comment.
Comments
2 comments