techrows = arcpy.SearchCursor(psegGasGDB_InputPrefix + "ASSIGNED_TECHS") for row in techrows: if TechID != row.ASSIGNED_USER: TechID = row.ASSIGNED_USER where_clause = "ASSIGNED_USER = " + TechID rows = arcpy.UpdateCursor(CONVERSION_InputPrefix + "CPTestPointInspection", where_clause, "SEQ_NO; GAS_CORR_STRUCT_NO", "GAS_CORR_STRUCT_NO") for row in rows: try: print row stop = 1 row.SetValue("SEQ_NO", stop) stop = stop + 1 except Exception as e: print e logging.error(": %s" %(e)) del rows del techrows
Solved! Go to Solution.
where_clause = "ASSIGNED_USER = " + TechID
where_clause = """ "ASSIGNED_USER" = """ + TechID # if TechID is numeric where_clause = """ "ASSIGNED_USER" = """ + "'"+TechID+"'" # if TechID is string
del techrows
lookupDict = {} searchRows = arcpy.SearchCursor(psegGasGDB_InputPrefix + "ASSIGNED_TECHS") searchRow = searchRows.next() while searchRow: lookupDict[searchRow.TECH_ID] = [searchRow.TECH_ID] where_clause = """ "ASSIGNED_USER" = """ + "'"+searchRow.TECH_ID+"'" updatecursor = arcpy.UpdateCursor(CONVERSION_InputPrefix + "CPTestPointInspection", where_clause, "", "SEQ_NO; GAS_CORR_STRUCT_NO", "GAS_CORR_STRUCT_NO") stop = 0 fldSEQNO = "SEQ_NO" for row in updatecursor: try: print stop stop = stop + 1 row.setValue(fldSEQNO, stop) cursor.updateRow(row) except Exception as e: print e logging.error(": %s" %(e)) searchRow = searchRows.next() del searchRow del searchRows
UPDATE CPTESTPOINTINSPECTION SET CPTESTPOINTINSPECTION.SEQ_NO = seq FROM ( SELECT t.TECH_ID,i.GAS_CORR_STRUCT_NO, INSPECTIONDATE, SEQ_NO, ROW_NUMBER() OVER (PARTITION BY t.TECH_ID ORDER BY i.GAS_CORR_STRUCT_NO) AS Seq FROM ASSIGNED_TECHS t INNER JOIN GISDG..CONVERSION.CPTESTPOINTINSPECTION i ON i.ASSIGNED_USER = t.TECH_ID ) CPTESTPOINTINSPECTION WHERE CPTESTPOINTINSPECTION.INSPECTIONDATE IS NULL