SelctByAttribute not working

109
2
Jump to solution
05-12-2020 09:36 AM
jaykapalczynski
Frequent Contributor

I am having issues with a a WHEREClause....anyone see anything wrong here.

THIS WORKS FINE

inputFeatureclass = r"E:/ArcGISProjects/County/xxx.sde/FeatureClassName"
dataInputParameter2 = "{9A35172E-071F-4A33-B191-172A9B4B02AE}"
whereClause = "FIELDNAME = " + "'" + dataInputParameter2 + "'"
fields = ['ID', 'FIELDNAME', 'UNIQUEID', 'OBJECTID']

with arcpy.da.SearchCursor(inputFeatureclass, fields, whereClause) as cursor:
    for row in cursor:
        print "--QUERY RESULT FROM MAIN FEATURE SERVICE ------"
        print('{0}, {1}, {2}, {3}'.format(row[0], row[1], row[2], row[3]))
        print ""‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

BUT NOW TRYING TO USE -- SelectByAttrbute

inputFeatureclass = r"E:/ArcGISProjects/County/xxx.sde/FeatureClassName"
dataInputParameter2 = "{9A35172E-071F-4A33-B191-172A9B4B02AE}"
whereClause = "FIELDNAME = " + "'" + dataInputParameter2 + "'"

results2 = arcpy.SelectLayerByAttribute_management(inputFeatureclass, 'NEW_SELECTION', whereClause)‍‍‍‍‍‍‍

Now I get this error when trying SelectByAttrbute

NOTE:  This is a GUID field data type in SDE SQL Server db

Traceback (most recent call last):
File "E:\ArcGISProjects\County\Python\UpdateGeometryJSON.py", line 94, in <module>
results2 = arcpy.SelectLayerByAttribute_management(inputFeatureclass, 'NEW_SELECTION', whereClause)
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 7744, in SelectLayerByAttribute
raise e
ExecuteError: Failed to execute. Parameters are not valid.
The value cannot be a feature class
ERROR 000840: The value is not a Raster Layer.
ERROR 000840: The value is not a Mosaic Layer.
Failed to execute (SelectLayerByAttribute).

0 Kudos
1 Solution

Accepted Solutions
jaykapalczynski
Frequent Contributor

Changed to this and it worked.

used MakeFeatureLayer_management and feed the results2 the variable

## SET THE TARGET FEATURE CLASS TO ADD THE FINAL MULTI PART GEOMETRY TO
inputFeatureclass = r"E:/ArcGISProjects/CountySelection/xxx.sde/FeaureClass"

arcpy.MakeFeatureLayer_management(r"E:/ArcGISProjects/County/xxx.sde/FeatureClass", "multiPart_lyr")


whereClause = "NWTLID = " + "'" + dataInputParameter2 + "'"

results2 = arcpy.SelectLayerByAttribute_management('multiPart_lyr', 'NEW_SELECTION', whereClause)

View solution in original post

0 Kudos
2 Replies
DavidPike
MVP Frequent Contributor

I thought this was solved in your post yesterday?

Needs to be turned into a layer

arcpy.MakeFeatureLayer_management 

0 Kudos
jaykapalczynski
Frequent Contributor

Changed to this and it worked.

used MakeFeatureLayer_management and feed the results2 the variable

## SET THE TARGET FEATURE CLASS TO ADD THE FINAL MULTI PART GEOMETRY TO
inputFeatureclass = r"E:/ArcGISProjects/CountySelection/xxx.sde/FeaureClass"

arcpy.MakeFeatureLayer_management(r"E:/ArcGISProjects/County/xxx.sde/FeatureClass", "multiPart_lyr")


whereClause = "NWTLID = " + "'" + dataInputParameter2 + "'"

results2 = arcpy.SelectLayerByAttribute_management('multiPart_lyr', 'NEW_SELECTION', whereClause)
0 Kudos