Thanks mate.
I didn’t want to bore everyone with the full code as this is a small part of the script.
What I was hoping to do was to simply add an “expression” to either the SelectLayerByAttribute command, or the MakeFeatureLayer command.
(apologies if the format of this code is not what is required).
inFeatures = "MasterFC"
layerName = "Temp"
inField = "ID"
joinTable = "text”
joinField = "Name"
qry = "[Version] = (SELECT MAX() from MasterFC GROUP BY )"
expression = "text.type = ‘active’”
outFeature = “NewTable”
arcpy.MakeFeatureLayer_management (inFeatures, layerName)
arcpy.SelectLayerByAttribute_management(layerName, "NEW_SELECTION", qry)
arcpy.AddJoin_management(layerName, inField, joinTable, joinField)
arcpy.SelectLayerByAttribute_management(layerName, "NEW_SELECTION", expression)
arcpy.CopyFeatures_management(layerName, outFeature)
In the above example I get “ERROR 000358: Invalid expression”
If I modify this to this placing the “qry” in the MakeFeatureLayer command:
arcpy.MakeFeatureLayer_management (inFeatures, layerName, qry)
arcpy.SelectLayerByAttribute_management(layerName, "NEW_SELECTION", qry)
arcpy.AddJoin_management(layerName, inField, joinTable, joinField)
arcpy.SelectLayerByAttribute_management(layerName, "NEW_SELECTION", expression)
arcpy.CopyFeatures_management(layerName, outFeature)
I get an error again with the query….
ERROR 000230: Failed selecting with = (SELECT MAX()
I guess my question is whether it can done this way using an expression parameter in either command? I’m thinking my expression is completely wrong…
Or should I be using a Search cursor with an expression?
And yes – there can potentially be different “versions” for each “ID”…..eg ID A, Version 1, ID C, Version 3, ID F, Version 2 etc…
The Feature Class is not versioned.
Many thanks,
Tim