Its been years since I last had to code, so please excuse the following.

The idea here is that a user inputs their work and it checks for missing expected data. (I've taken out other code that works but is for other checks)

Simplified summary of what I'd like it to do:

Identify which data set (MASTER_ID) is being added.

Select all records from the masterTable that have that MASTER_ID.

Compare these selected records against userTable by Join based on KEY

If there is a record found in masterTable and not found in userTable, (NULL record found in joined userTable) output Key from masterTable for that row as an error.

-Key =unique string eg. 12345678-A123

-MASTER_ID =same for entire UserSubmitTable eg. 12345678

land = arcpy.GetParameterAsText(0)
area = arcpy.GetParameterAsText(1)

#Join Land & Area tables#
landList = "landList"
arcpy.JoinField_management(land, 'KEY', area, 'KEY', ['ID_land', 'land_NO','MASTER_ID'])
arcpy.Frequency_analysis(land, landList, ['KEY', 'land_NO','MASTER_ID'])

#get the active MASTER_ID as string #
for row in arcpy.da.SearchCursor(area, ['MASTER_ID']):
    if row[0] is not None:
        Active_ID = row[0]

#query MASTER_ID #
queryList = "query_table"
arcpy.MakeQueryTable_management(landList, queryList, "NO_KEY_FIELD", "MASTER_ID = '{}'".format(Active_ID))

#search for errors #
for row in arcpy.da.SearchCursor(queryList, ['land_NO', 'MASTER_ID', 'KEY']):
    if row[0] is None and row[1] is not None:#
        arcpy.AddError(row[2] + " exist in reference but is missing")

I get:

\management.py", line 7441, in MakeQueryTable raise e RuntimeError: Object: Error in executing tool

  • 3
    All data must reside in the same database or geodatabase. Also, there is a Table Compare tool might be helpful. – klewis Mar 19 '19 at 18:24
  • That fixed it, I had created a separate gdb to test in but didn't transfer the reference table into it. However it seems the query is applied to the entire table so I'll investigate the Table Compare tool. – StaleDoughnut Mar 19 '19 at 18:46
  • You can pass in a Where Clause when running MakeQueryTable, it's the last parameter. – klewis Mar 19 '19 at 20:09

Browse other questions tagged or ask your own question.