<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Copy an attribute value from one table to another, based on matching key attribut in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/copy-an-attribute-value-from-one-table-to-another/m-p/128091#M9954</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try changing your workspace to the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;env.workspace = "database connections\connection to db.sde"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You are missing the '.sde' for the connection file, and you will not have to specify the database name and owner.&amp;nbsp; Python will use the credentials stored within the SDE connection file.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 27 Jun 2012 11:28:31 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2012-06-27T11:28:31Z</dc:date>
    <item>
      <title>Copy an attribute value from one table to another, based on matching key attributes</title>
      <link>https://community.esri.com/t5/python-questions/copy-an-attribute-value-from-one-table-to-another/m-p/128088#M9951</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to write a python script to copy an attribute value from one table to an attribute in another table, based on a primary key to foreign key match.&amp;nbsp; Basically, this is a workaround for relating an '_ATTACH' table to its parent table's record (the attachment record was created outside of Arc, so the 'REL_OBJECTID' attribute does not automatically get populated with the parent tables' record's 'OBJECTID', so I am trying to systematically repair this link).&amp;nbsp; I cannot figure out the syntax in using an updatecurser (or even if this is the way to do this!).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let's say that I have a table, 'Table1' with a primary key, PK_GUID, field that is populated, and it has a system created attachment table, 'Table1_ATTACH' with a foreign key, FK_GUID, populated with the parent's primary key value (this is the link I can use in my where clause to link the records):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I need for the attribute Table1_ATTACH.REL_OBJECTID to be populated with Table1.OBJECTID&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I attempted to write a script to do this, mimicking some bad code I found in my google search:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;#define the parent table Table2 = r"database connections\connection to db\db.DBO.Table1__ATTACH"&amp;nbsp; #create a cursor on the child table's record that is linked to the parent table's record on the non-ESRI keys Rows = arcpy.UpdateCursor("db.DBO.Table1__ATTACH", "select * from db.DBO.Table1 where db.DBO.Table1.PK_GUID = db.DBO.Table1_ATTACH.FK_GUID", "", "REL_OBJECTID") for row in rows:&amp;nbsp; row.REL_OBJECTID = T2.OBJECTID &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Am I anywhere near close on this one?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Jun 2012 17:13:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copy-an-attribute-value-from-one-table-to-another/m-p/128088#M9951</guid>
      <dc:creator>MatthewWalker1</dc:creator>
      <dc:date>2012-06-05T17:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: Copy an attribute value from one table to another, based on matching key attribut</title>
      <link>https://community.esri.com/t5/python-questions/copy-an-attribute-value-from-one-table-to-another/m-p/128089#M9952</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Matt,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It's actually a little tricky to calculate field values from one table to another outside of ArcMap.&amp;nbsp; Here is some sample code that I was able to get to work:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy from arcpy import env env.workspace = r"C:\temp\python\test.gdb"&amp;nbsp; fc = "Airports" table = "Airports__ATTACH"&amp;nbsp; # Add a field to the feature class and calculate the OBJECTIDs to this new field arcpy.AddField_management(fc, "OBJECTID2", "LONG") arcpy.CalculateField_management(fc, "OBJECTID2", "!OBJECTID!", "PYTHON_9.3")&amp;nbsp; # Join the new OBJECTID2 field to the attachment table (original OBJECTID will not join) arcpy.JoinField_management(table, "FK_GUID", fc, "PK_GUID", "OBJECTID2")&amp;nbsp; # Update the REL_OBJECTID field with the OBJECTID2 values rows = arcpy.UpdateCursor(table) for row in rows: &amp;nbsp;&amp;nbsp;&amp;nbsp; row.REL_OBJECTID = row.OBJECTID2 &amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)&amp;nbsp; del row, rows&amp;nbsp; # Delete the OBJECTID2 fields from the feature class and table arcpy.DeleteField_management(fc, "OBJECTID2") arcpy.DeleteField_management(table, "OBJECTID2")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jun 2012 11:04:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copy-an-attribute-value-from-one-table-to-another/m-p/128089#M9952</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2012-06-06T11:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: Copy an attribute value from one table to another, based on matching key attribut</title>
      <link>https://community.esri.com/t5/python-questions/copy-an-attribute-value-from-one-table-to-another/m-p/128090#M9953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi Matt,&lt;BR /&gt;&lt;BR /&gt;It's actually a little tricky to calculate field values from one table to another outside of ArcMap.&amp;nbsp; Here is some sample code that I was able to get to work:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
from arcpy import env
env.workspace = r"C:\temp\python\test.gdb"

fc = "Airports"
table = "Airports__ATTACH"

# Add a field to the feature class and calculate the OBJECTIDs to this new field
arcpy.AddField_management(fc, "OBJECTID2", "LONG")
arcpy.CalculateField_management(fc, "OBJECTID2", "!OBJECTID!", "PYTHON_9.3")

# Join the new OBJECTID2 field to the attachment table (original OBJECTID will not join)
arcpy.JoinField_management(table, "FK_GUID", fc, "PK_GUID", "OBJECTID2")

# Update the REL_OBJECTID field with the OBJECTID2 values
rows = arcpy.UpdateCursor(table)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.REL_OBJECTID = row.OBJECTID2
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)

del row, rows

# Delete the OBJECTID2 fields from the feature class and table
arcpy.DeleteField_management(fc, "OBJECTID2")
arcpy.DeleteField_management(table, "OBJECTID2")&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure what I am doing wrong here, I took your code, changed the env.workspace and featureclass and ATTACH table and tried to run it through the cmd prompt, and keep getting an error stating the dataset does not exist.&amp;nbsp; Here is my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
from arcpy import env
env.workspace = "database connections\connection to db\Fire.DBO"

fc = "Event"
table = "Event__ATTACH"
# Add a field to the feature class and calculate the OBJECTIDs to this new field
print "attempting to add field..."
arcpy.AddField_management(fc, "OBJECTID2", "LONG")
print "added field 'OBJECTID2'..."
arcpy.CalculateField_management(fc, "OBJECTID2", "!OBJECTID!", "PYTHON_9.3")
print "Calculated field..."
# Join the new OBJECTID2 field to the attachment table (original OBJECTID will not join)
arcpy.JoinField_management(table, "FK_GUID", fc, "PK_GUID", "OBJECTID2")

# Update the REL_OBJECTID field with the OBJECTID2 values
rows = arcpy.UpdateCursor(table)
for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; row.REL_OBJECTID = row.OBJECTID2
&amp;nbsp;&amp;nbsp;&amp;nbsp; rows.updateRow(row)

del row, rows

# Delete the OBJECTID2 fields from the feature class and table
arcpy.DeleteField_management(fc, "OBJECTID2")
arcpy.DeleteField_management(table, "OBJECTID2")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and here is the error message, from the cmd prompt:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;C:\Users\matt\Desktop&amp;gt;AttachTableJoins.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;attempting to add field...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Users\matt\Desktop\AttachTableJoins.py", line 9, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc, "OBJECTID2", "LONG")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py",&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ne 2625, in AddField&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000732: Input Table: Dataset Event does not exist or is not supported&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (AddField).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I know the tables are there and there are no feature datasets in the database, so I don't know what that error message is coming from.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:14:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copy-an-attribute-value-from-one-table-to-another/m-p/128090#M9953</guid>
      <dc:creator>MatthewWalker1</dc:creator>
      <dc:date>2021-12-11T07:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: Copy an attribute value from one table to another, based on matching key attribut</title>
      <link>https://community.esri.com/t5/python-questions/copy-an-attribute-value-from-one-table-to-another/m-p/128091#M9954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try changing your workspace to the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;env.workspace = "database connections\connection to db.sde"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You are missing the '.sde' for the connection file, and you will not have to specify the database name and owner.&amp;nbsp; Python will use the credentials stored within the SDE connection file.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jun 2012 11:28:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copy-an-attribute-value-from-one-table-to-another/m-p/128091#M9954</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2012-06-27T11:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Copy an attribute value from one table to another, based on matching key attribut</title>
      <link>https://community.esri.com/t5/python-questions/copy-an-attribute-value-from-one-table-to-another/m-p/128092#M9955</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Try changing your workspace to the following:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;env.workspace = "database connections\connection to db.sde"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;You are missing the '.sde' for the connection file, and you will not have to specify the database name and owner.&amp;nbsp; Python will use the credentials stored within the SDE connection file.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That. Is. Awesome!&amp;nbsp; Thank you, that resolved my issue and I was able to run the script!&amp;nbsp; This gets me one step closer to utilizing the 'Attach' table and photo display support I am looking for.&amp;nbsp; Thanks again for your insight into this issue!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 27 Jun 2012 14:55:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copy-an-attribute-value-from-one-table-to-another/m-p/128092#M9955</guid>
      <dc:creator>MatthewWalker1</dc:creator>
      <dc:date>2012-06-27T14:55:56Z</dc:date>
    </item>
  </channel>
</rss>

