BrokenLegMike

Cursor Searching 2 tables and Updating a 3rd

Discussion created by BrokenLegMike on Jun 14, 2012
Latest reply on Jun 18, 2012 by BrokenLegMike
Hey everyone,

I am trying to:


  1. Set a search cursor through table 1 which contains 2 fields. S_RANK and DESCRIPTION

  2. within the first loop, I am cursor searching through Table 2 which contains 2 fields. G_RANK and DESCRIPTION

  3. Updating a cursor on table 3 which contains 2 fields. ANHIC_RANK and DESCRIPTION


In the update cursor, I want to populate ANHIC_RANKING field in table 3 with a concatenation of S_RANK + G_RANK from the first. I want to update the DESCRIPTION field in table 3 with a concatenation of the 2 DESCRIPTION fields from the first 2 tables (i.e. DESCRIPTION + " + " + DESCRIPTION)

The print statements in the first 2 loops print out fine, it's the update cursor that doesn't seem to update. Any suggestions?

Thanks,
Mike

import arcpy
from arcpy import env

env.workspace = r"Z:\IOR\2012\2012_Geodatabase_UTM\DOMAIN_CODE_TABLES.gdb"

for x in arcpy.SearchCursor("ANHIC_RANK_S"):
    print x.S_RANK
    print x.DESCRIPTION

    for y in arcpy.SearchCursor("ANHIC_RANK_G"):
        print y.G_RANK
        print y.DESCRIPTION

        with arcpy.da.UpdateCursor("ANHIC_RANKING_FINAL", ["ANHIC_RANKING", "DESCRIPTION"]) as cursor:

            for row in cursor:
                row.ANHIC_RANKING = x.S_RANK + y.G_RANK
                row.DESCRIPTION = x.DESCRIPTION + " + " + y.DESCRIPTION
                c.updateRow(row)

Outcomes