I have three variables: view_name, column_name, and column_content.

column_name contains id, name, address, etc. column_content contains 123, John, 200 King st, etc.

user specifies the column_name and column_content

a SDE connection file located: c:\gdb.dmz.sde

how to query the database in the view = view_name where column_name = column_content?

using arcpy.da.SearchCursor() function.

  • 1
    What are you wanting to get out - if the user provides the column name and content - are you just looking for a count of the matching records?
    – dklassen
    Commented Apr 4, 2014 at 17:39

1 Answer 1


It sounds like column_name is your field name, and column_content is the value you are looking for. Using da.SearchCursor will certainly get you where you want to be. I am assuming you then wish to find other information from the row once the row is matched. To get this information, the da.SearchCursor requires the feature class or table you wish to query and a list of fields you wish to find the values of as its inputs. The cursor returns a tuple of the values in the fields you indicated as your da.SearchCursor input. You can use an if statement to find the value you are after.

Something like this:

fc = r"feature/class/full/path"

column_name = "ADDRESS"
column_content = "123 Way Street"

otherfields = ["ID", "NAME", "ADDRESS"]

fields = [column_name] + otherfields

cursor = arcpy.da.SearchCursor (fc, fields)
for row in cursor:
    if row[0] == column_content:
        print "ID:", row[1]
        print "NAME:", row[2]
        print "ADDRESS:", row[3]
del row
del cursor

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.