<?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 I need help, I want to label a layer using SQL Query i.e a Primary and Foreign Key in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/i-need-help-i-want-to-label-a-layer-using-sql/m-p/403876#M31795</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to label a layer using SQL Query i.e a Primary and Foreign Key, the primary key field is the OBJECTID in the polygon layer while the ParcelID is the Foreign Key field in the Line_Clip layer. Below is my script but it is not working;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument("Current") lyr = "Lines_Clip" lyr1 = "Parcels_Clip" field1 = "OBJECTID" field2 = "ParcelID" for lyr in arcpy.mapping.ListLayers(mxd): &amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("LABELCLASSES"): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.showLabels: &amp;nbsp; where "ParcelID" = "OBJECTID"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What im i doing wrong?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 01 Sep 2012 00:13:18 GMT</pubDate>
    <dc:creator>OLANIYANOLAKUNLE</dc:creator>
    <dc:date>2012-09-01T00:13:18Z</dc:date>
    <item>
      <title>I need help, I want to label a layer using SQL Query i.e a Primary and Foreign Key</title>
      <link>https://community.esri.com/t5/python-questions/i-need-help-i-want-to-label-a-layer-using-sql/m-p/403876#M31795</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to label a layer using SQL Query i.e a Primary and Foreign Key, the primary key field is the OBJECTID in the polygon layer while the ParcelID is the Foreign Key field in the Line_Clip layer. Below is my script but it is not working;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument("Current") lyr = "Lines_Clip" lyr1 = "Parcels_Clip" field1 = "OBJECTID" field2 = "ParcelID" for lyr in arcpy.mapping.ListLayers(mxd): &amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.supports("LABELCLASSES"): &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.showLabels: &amp;nbsp; where "ParcelID" = "OBJECTID"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What im i doing wrong?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Sep 2012 00:13:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/i-need-help-i-want-to-label-a-layer-using-sql/m-p/403876#M31795</guid>
      <dc:creator>OLANIYANOLAKUNLE</dc:creator>
      <dc:date>2012-09-01T00:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: I need help, I want to label a layer using SQL Query i.e a Primary and Foreign Ke</title>
      <link>https://community.esri.com/t5/python-questions/i-need-help-i-want-to-label-a-layer-using-sql/m-p/403877#M31796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;First you need to join the two data sources.&amp;nbsp; Once joined, you can use a script that is simlar to the one in the help:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/#/LabelClass/00s30000002t000000/" rel="nofollow noopener noreferrer" target="_blank"&gt;http://resources.arcgis.com/en/help/main/10.1/#/LabelClass/00s30000002t000000/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
mxd = arcpy.mapping.MapDocument("current")
lyr = arcpy.mapping.ListLayers(mxd, "Lines_Clip")[0]
for lblClass in lyr.labelClasses:
&amp;nbsp;&amp;nbsp;&amp;nbsp; lblClass.expression = "[table.ParcelID]"&amp;nbsp;&amp;nbsp; #NOTE - SQL syntax could be different depending on data source
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jeff&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:24:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/i-need-help-i-want-to-label-a-layer-using-sql/m-p/403877#M31796</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2021-12-11T18:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: I need help, I want to label a layer using SQL Query i.e a Primary and Foreign Ke</title>
      <link>https://community.esri.com/t5/python-questions/i-need-help-i-want-to-label-a-layer-using-sql/m-p/403878#M31797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks i got a workaround for it; let me share my code&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.SelectLayerByLocation_management("Parcels", "COMPLETELY_WITHIN", "ClipFeature", "", "NEW_SELECTION") fc = "Parcels" field = "OBJECTID" cursor = arcpy.SearchCursor(fc) for row in cursor: &amp;nbsp;&amp;nbsp;&amp;nbsp; val = row.getValue(field) &amp;nbsp;&amp;nbsp;&amp;nbsp; print (row.getValue(field)) &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mxd = arcpy.mapping.MapDocument("current") lyr = arcpy.mapping.ListLayers(mxd, "Lines_Clip")[0] for lblClass in lyr.labelClasses: &amp;nbsp;&amp;nbsp;&amp;nbsp; lblClass.SQLQuery = '"ParcelID"' + "=" + str(val)&amp;nbsp; arcpy.SelectLayerByAttribute_management("Parcels", "CLEAR_SELECTION") &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 08 Sep 2012 01:27:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/i-need-help-i-want-to-label-a-layer-using-sql/m-p/403878#M31797</guid>
      <dc:creator>OLANIYANOLAKUNLE</dc:creator>
      <dc:date>2012-09-08T01:27:56Z</dc:date>
    </item>
  </channel>
</rss>

