AnsweredAssumed Answered

Select by attribute SQL statement

Question asked by Carusot42 on Jan 20, 2015
Latest reply on Jan 21, 2015 by jamesfreddyc

Hi folks,

 

I'm having an issue with an SQL statement for the select layer by attribute function and I can't figure out what's going on, because it worked perfectly on a smaller dataset, but when I try to run it on a larger selection of data it fails and gives me an error. Here is the offending piece of code:

 

for key in matches:
        arcpy.SelectLayerByAttribute_management(wellsFL, "NEW_SELECTION", "U_ID = {}".format(key))
        select_id = tuple(matches[key])
        arcpy.SelectLayerByAttribute_management(orpsFL, "NEW_SELECTION", "U_ID IN {}".format(select_id))

 

the issue is line # 4. "matches" is a dictionary that stores a well ID with a list of ID's of potential orps matches. I want line 4 to select all the orps that have U_ID's in a particular entry of the dictionary.

 

Like I said, when testing this on a smaller dataset, it worked perfectly fine. But now that I try it on a full town's worth of wells/orps, it fails, giving the following error code:

 

Traceback (most recent call last):

  File "<pyshell#8>", line 1, in <module>

    arcpy.SelectLayerByAttribute_management(orpsFL, "NEW_SELECTION", "U_ID = {}".format(select_id))

  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 6494, in SelectLayerByAttribute

    raise e

ExecuteError: ERROR 000358: Invalid expression

Failed to execute (SelectLayerByAttribute).

 

What is suddenly making this expression invalid??

 

Thanks in advance,

 

Tom

Outcomes