query

926
9
04-28-2020 08:46 AM
CrystalCraig
New Contributor

I am using ArcGIS Pro and have a list of APNs to Query. I did the expression:

"APN"='186250009'Or"APN"='186250013'Or"APN"=186250007Or"APN"=186250005Or"APN"=186250004Or"APN"=186250003Or"APN"=186260020Or"APN"=186250002

And it's not working.

Am I doing something wrong? Do I use "Select by Attributes" and use the SQL or do I open the Attribute table and hit "Calculate" within the Calculate Field and write the expression there. 

Thank you!

0 Kudos
9 Replies
DavidPike
MVP Frequent Contributor

What is the query for? is it a select by attribute, definition query etc?

is the APN a number or string? if it's a number get rid of the quotes.

you could also use the IN operator for efficiency:

"APN" IN (12344, 123124, 142442)

0 Kudos
CrystalCraig
New Contributor

It would be to select by attribute

0 Kudos
CrystalCraig
New Contributor

They Query is to select certain parcels, to illustrate just those parcels.  I have about 50 of them. I am not sure which route I should go, I usually do it in the "Select Layer by Attributes" but if it's just one or I go in and select the parcels and then make a new layer out of it, but I have parcels that are not all in the same area. I hope this makes sense. 

0 Kudos
DavidPike
MVP Frequent Contributor

I've checked this in pro (don't use it much) and the column names have no quotation now, i'd try that

0 Kudos
CrystalCraig
New Contributor

Thank you David, I will give it a try. 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

In ArcGIS Pro, and in ArcGIS Desktop for quite a few years, the names of file geodatabase fields can be double quoted or not.  Double quotes used to be required, and although they have been phased out, they are still supported for backwards compatibility. 

JoeBorgione
MVP Emeritus

On the right side of my screen capture below, you'll see how I just constructed a query for parcel ids (ours are of text type to). In the  select by attribute dialog, I just clicked on values; notice there are no quotes there.  It took me quite a while to get used to that with ArcGIS Pro.

However, if you look at the history/details pane on the left side of the image, you'll notice the quotes around the values.  It might be 

Switching to the SQl view (see below) notice how the expression is written.  Could it be that your syntax without spaces are giving you the problem? Notice to the lack of quotes around the field name (parcel_id)

That should just about do it....
JoshuaBixby
MVP Esteemed Contributor

Regarding:

And it's not working.

It helps to elaborate.  What isn't working, specifically?  Are you getting an error?  If so, what?  Are you getting unexpected results?  If so, what are you expecting and what are you getting?

In terms of overall approach, I agree with David Pike‌ in that you should use the SQL IN operator:

APN IN ('186250009', '186250013', '186250007', '186250005', '186250004', '186250003', '186260020', '186250002')

Also, in looking at your code you posted, you are using non-ASCII single quotes around some of the APN codes.  For SQL queries, the single quotes need to be ASCII single quotes:  CHAR(39) .

0 Kudos
CrystalCraig
New Contributor

Thank you Joe, David and Joshua, It was being a pain, this is the expression that worked:

APN = '186250009' Or APN = '186250013' and etc...

I was also able to save my Expression and also check where it says "Ivert where Clause"

0 Kudos