<?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 Unable to read data from Query Layer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283357#M21884</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm unable to use Python/Geoprocessing to read data from an ESRI Query Layer. How can I make this work?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried two things:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) Use Make Feature Layer to read from .lyr&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Reference: &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/584-beta-10-system-tool-for-extracting-query-layer-data-to-file-gdb" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/584-beta-10-system-tool-for-extracting-query-layer-data-to-file-gdb&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code explained: Works for .lyr based on layer (data source is sde spatial view which arcgis sees as a feature class). Does not work for .lyr based on query layer (data source is sde view which arcgis sees as a table).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import system modules
import sys, string, os, arcpy

arcpy.AddMessage("start script....")

#lyr = "C:\Projects\BranchMapping\dev\src\GP_Tasks\ppOwner.lyr"
lyr = "C:\Projects\BranchMapping\dev\src\GP_Tasks\BRANCHES.lyr"

#qry = "KeyInstn = 4001616" # D
qry = "KeyInstn = 4019974" # VABK

arcpy.AddMessage("Making feature layer....")
arcpy.MakeFeatureLayer_management(lyr, "lyr", qry)

arcpy.AddMessage("Getting count....")
result = arcpy.GetCount_management("lyr")

count = int(result.getOutput(0))
arcpy.AddMessage(str(count))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2) MakeQueryTable &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Reference: &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/25496-Query-Layer?highlight=query+layer+geoprocessing+python" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/25496-Query-Layer?highlight=query+layer+geoprocessing+python&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Opening the tool I browse to the sde view. Afterwards I get this error: ERROR 000793&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Invalid data element type ERROR 000840: The value is not a Raster Layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I read the doc, but I don't understand. Can I use this tool to create a layer from a "query layer" table data source (i.e. same data source that I can use to create a Query Layer in ArcMap).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does ESRI have a way to use PY to read data from a Query Layer data source?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Cory&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 13:43:04 GMT</pubDate>
    <dc:creator>deleted-user-Ohz6rwd1kavx</dc:creator>
    <dc:date>2021-12-11T13:43:04Z</dc:date>
    <item>
      <title>Unable to read data from Query Layer</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283357#M21884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm unable to use Python/Geoprocessing to read data from an ESRI Query Layer. How can I make this work?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've tried two things:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) Use Make Feature Layer to read from .lyr&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Reference: &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/584-beta-10-system-tool-for-extracting-query-layer-data-to-file-gdb" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/584-beta-10-system-tool-for-extracting-query-layer-data-to-file-gdb&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code explained: Works for .lyr based on layer (data source is sde spatial view which arcgis sees as a feature class). Does not work for .lyr based on query layer (data source is sde view which arcgis sees as a table).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import system modules
import sys, string, os, arcpy

arcpy.AddMessage("start script....")

#lyr = "C:\Projects\BranchMapping\dev\src\GP_Tasks\ppOwner.lyr"
lyr = "C:\Projects\BranchMapping\dev\src\GP_Tasks\BRANCHES.lyr"

#qry = "KeyInstn = 4001616" # D
qry = "KeyInstn = 4019974" # VABK

arcpy.AddMessage("Making feature layer....")
arcpy.MakeFeatureLayer_management(lyr, "lyr", qry)

arcpy.AddMessage("Getting count....")
result = arcpy.GetCount_management("lyr")

count = int(result.getOutput(0))
arcpy.AddMessage(str(count))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2) MakeQueryTable &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Reference: &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/25496-Query-Layer?highlight=query+layer+geoprocessing+python" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/25496-Query-Layer?highlight=query+layer+geoprocessing+python&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Opening the tool I browse to the sde view. Afterwards I get this error: ERROR 000793&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Invalid data element type ERROR 000840: The value is not a Raster Layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I read the doc, but I don't understand. Can I use this tool to create a layer from a "query layer" table data source (i.e. same data source that I can use to create a Query Layer in ArcMap).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does ESRI have a way to use PY to read data from a Query Layer data source?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Cory&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:43:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283357#M21884</guid>
      <dc:creator>deleted-user-Ohz6rwd1kavx</dc:creator>
      <dc:date>2021-12-11T13:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to read data from Query Layer</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283358#M21885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just having a look, a couple things come to mind. First off, if your input is already a layer, it shouldn't need a conversion to a feature layer...it already is. The script may be confusing itself with that logic. Try just getting a count on the lyr instead of "lyr"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The second thought you might try is to see if your layer is being sourced properly to the underlying feature class. Go into catalog and navigate to the layer file. Right click and go into properties to see if it has a source. Then, go to table view and see if there is any data in the table. If there isn't, then either the underlying feature class is empty or the source isn't connecting properly.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Finally, I don't work in sde and know very little about it, but maybe check how your query is built. Queries on fields are built differently based on personal and file geodatabases. If in doubt, I build a test model and export to script to see how the query syntax should be built.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyways, hope some of this helps.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Mar 2012 17:47:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283358#M21885</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2012-03-20T17:47:52Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to read data from Query Layer</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283359#M21886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Mike&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the advice. I am getting closer...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Example 1 (based on your tip, thanks!) works...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# Import system modules
import sys, string, os, arcpy

arcpy.AddMessage("start script....")

lyr = "C:\Temp\gpFun\BRANCHES_VABK.lyr" # includes query

arcpy.AddMessage("Getting count....")
result = arcpy.GetCount_management(lyr)

count = int(result.getOutput(0))
arcpy.AddMessage(str(count))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;... now, how to apply query external to the .lyr definition.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Example 2 Select layer by attribute fails....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import system modules
import sys, string, os, arcpy

arcpy.AddMessage("start script....")

lyr = "C:\Temp\gpFun\BRANCHES.lyr"

qry = "KeyInstn = 4019974" # VABK
arcpy.AddMessage(qry)

arcpy.AddMessage("Selecting layer by attribute....")
arcpy.SelectLayerByAttribute_management (lyr, "NEW_SELECTION", qry)

arcpy.AddMessage("Getting count....")
result = arcpy.GetCount_management(lyr)

count = int(result.getOutput(0))
arcpy.AddMessage(str(count))
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;.... here is the error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: Failed to execute. Parameters are not valid.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000825: The value is not a layer or table view&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000840: The value is not a Raster Layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000840: The value is not a Mosaic Layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (SelectLayerByAttribute).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Example 3 uses TableSelect...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Import system modules
import sys, string, os, arcpy

arcpy.AddMessage("start script....")

lyr = "C:\Temp\gpFun\BRANCHES.lyr"

qry = "KeyInstn = 4019974" # VABK
arcpy.AddMessage(qry)

arcpy.AddMessage("Table selecting....")
arcpy.TableSelect_analysis(lyr, "c:/temp/gpFun/tempOut.shp", qry)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;... this works, but the .shp is a table, not a feature class. This won't work for me. I need to perform spatial operations on this like buffer, etc.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Weird. I think there is some missing piece for "reading" Query Layers as features, not rows.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;BTW, Query Layers aren't geodatabase feature classes. They're actually tables in the DBMS with spatial columns. ESRI application then sees these as shapes. GP/Python seems to have problems seeing them though...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your help,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Cory&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 13:43:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283359#M21886</guid>
      <dc:creator>deleted-user-Ohz6rwd1kavx</dc:creator>
      <dc:date>2021-12-11T13:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to read data from Query Layer</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283360#M21887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Cory&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wonder whether you find the solution to your problem. I am on the same boat and looking for a possible solution.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Sep 2012 19:29:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283360#M21887</guid>
      <dc:creator>DeeptiPuri</dc:creator>
      <dc:date>2012-09-07T19:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to read data from Query Layer</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283361#M21888</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It seems to work if you add makefeaturelayer &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage("Making feature layer....")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lay = arcpy.MakeFeatureLayer_management(lyr, "lyr")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;qry = "NAME = 'TEST'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management (lay, "NEW_SELECTION", qry)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Olivier&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 15:07:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283361#M21888</guid>
      <dc:creator>OlivierOlivier</dc:creator>
      <dc:date>2012-09-24T15:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to read data from Query Layer</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283362#M21889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This works partially for me :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage("Making feature layer....")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lay = arcpy.MakeFeatureLayer_management(lyr, "lyr")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;qry = "CODE like 'COD%'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;res=arcpy.SelectLayerByAttribute_management (lay, "NEW_SELECTION",qry)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;curs = arcpy.SearchCursor(res,"","","CODE")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for row in curs:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage(str(row.CODE))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but as I'm not very skilled with arcpy, I don't understand why the filter doesn't work, res contains all objects (so SelectLayerByAttribute) is useless.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for any help.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Olivier&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Edit : But it works if I use qry in MakeFeatureLayer_Management, forgetting about&amp;nbsp; SelectLayerByAttribute. If someone can explain me my mistake, I would appreciate.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Sep 2012 16:35:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283362#M21889</guid>
      <dc:creator>OlivierOlivier</dc:creator>
      <dc:date>2012-09-24T16:35:18Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to read data from Query Layer</title>
      <link>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283363#M21890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What version of Arc are you using? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I did get this working based on your example. There may have been some small syntax errors in your code.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Try writing your lyr and qry like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#lyr = "C:\Projects\BranchMapping\dev\src\GP_Tasks\ppOwner.lyr"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr = r"C:\Projects\BranchMapping\dev\src\GP_Tasks\BRANCHES.lyr"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#qry = "KeyInstn = 4001616" # D&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;qry = "\"KeyInstn\" = 4001616" # VABK&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is a little more info on correct syntax within a where clause for Python here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//001700000071000000"&gt;http://resources.arcgis.com/en/help/main/10.1/index.html#//001700000071000000&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And the error that you are receiving when trying to use "SelectLayerByAttribute" may be fixed by using "MakeFeatureLayer" first which works as input for the Select Layer by Attribute tool. So basically something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import system modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys, string, os, arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#lyr = "C:\Projects\BranchMapping\dev\src\GP_Tasks\ppOwner.lyr"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lyr = r"C:\Projects\BranchMapping\dev\src\GP_Tasks\BRANCHES.lyr"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#qry = "KeyInstn = 4001616" # D&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;qry = "\"KeyInstn\" = 4001616" # VABK&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# You do need to make feature layer to use as input select layer by attribute&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MakeFeatureLayer_management(lyr,"lyr")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.SelectLayerByAttribute_management("lyr", "NEW_SELECTION", qry)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;result = arcpy.GetCount_management("lyr")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;count = int(result.getOutput(0))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage(str(count))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;[/HTML]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I hope that helps!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Sep 2012 18:11:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/unable-to-read-data-from-query-layer/m-p/283363#M21890</guid>
      <dc:creator>JohnPenney</dc:creator>
      <dc:date>2012-09-25T18:11:11Z</dc:date>
    </item>
  </channel>
</rss>

