I am trying to use the code below to allow testing of one field which contains mixed case against another field which contains uppercase only. I have read many many posts but they generally tend to look at converting or using Field Calc and I do not want the values to be converted. (only on the fly) I am using ArcGIS 10.2 Win 7 x64 and Python 27.

    # Refine the selection set to only 'LGA <> LGA_NAME'
    fn99 = "LGA"
    fn98 = "LGA_NAME"
    EXPR1 = fn99.upper() +"<>"+ fn98.upper()
    DEF1 = arcpy.SelectLayerByAttribute_management(fc_lyr2, "NEW_SELECTION", EXPR1)
    print "\n" "Using SelectLayerByAttribute to create a 'NEW_SELECTION' from " + fc_lyr2
    print DEF1.getMessages()

Note I dont get any errors, my code just doesnt test successfully so all values are retyurned and I know there are at least 50 incorrect values from manual checking.

  • 3
    You are uppercasing the field names (which are already in uppercase) and not the values in those fields. I would suggest adding a field (perhaps called flag) and then use an arcpy.da.UpdateCursor to set its value to 1 (to be used to later select it) when row[0].upper() <> row[1].upper(). Then SelectLayerByAttribute just grabs flag = 1.
    – PolyGeo
    Commented Oct 25, 2016 at 22:54

1 Answer 1


From the ArcGIS help topic "SQL reference for query expressions used in ArcGIS":

Strings are case sensitive in expressions. For feature classes and tables, you can use the UPPER or LOWER function to set the case for a selection.

(untested) Try changing this line: EXPR1 = "UPPER({}) <> UPPER({})".format(fn99, fn98)

  • +1 UPPER keyword is the way.
    – fatih_dur
    Commented Oct 25, 2016 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.