Select to view content in your preferred language

Format for Queries Connected with AND/OR

1444
5
05-19-2011 02:40 PM
ChrisFarver
Emerging Contributor
Hi,

I'm having a bit of trouble trying to find the correct format for connecting two queries together with AND. I feel I've tried so many different combinations, but haven't found a way that works.

What I'm trying to code is a query that searches through a list of houses/apartments by a specified range. At first I was using
query.where = "3_bedrooms <= " + rent;

But found that it would return a lot of properties, as many were initialized to having a rent of 0.

So I tried combining statements along the lines of
query.where = "3_bedrooms > " + 0 + "AND 3_bedrooms <= " + rent;

And many other variations of this line, but nothing seems to work. Been searching online for the correct format, but haven't found anything yet. Can anyone help me out?

Thanks
0 Kudos
5 Replies
derekswingley1
Deactivated User
I find the best place to test these things out is at your REST endpoint. You can play around with different syntax to see what actually works and then drop that in your app.

One thing about the where clause you posted:
query.where = "3_bedrooms > " + 0 + "AND 3_bedrooms <= " + rent;


I think you need another space before your AND:
query.where = "3_bedrooms > " + 0 + " AND 3_bedrooms <= " + rent;


Edit:  just to confirm, the datatype of the 3_bedrooms field is not a string, right?
0 Kudos
ChrisFarver
Emerging Contributor
Correct, the datatype for 3_bedrooms is an integer.

Correction: Got it to work. Thanks for the help
0 Kudos
derekswingley1
Deactivated User
Check out the where clause and the results here:  http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSWells/MapServer/0/query?&wher...

The where clause being used is:  SECTION > 0 and SECTION <= 2
0 Kudos
derekswingley1
Deactivated User
Glad to help. Care to elaborate on what fixed it for you?
0 Kudos
ChrisFarver
Emerging Contributor
Ah sorry I didn't see the other response.

I think it was just the proper placement of the quotation marks, but especially that extra space that you pointed out really did it. Now it's working like a charm.

Thanks again.
0 Kudos