<?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 MakeQueryTable_Management in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313906#M24389</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to create a table called "Test" from inputTable called "Avg_Daily" using arcpy.MakeQueryTable_Management option of arcpy. However, I am getting error which says "Error 999999: An Invalid SQL statement was used". I don't know where I used invalid SQL statement. Any idea? Here is the code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy from arcpy import env&amp;nbsp; env.workspace ="C:/RG/Projects/CriticalDataNetwork/CDEC.gdb"&amp;nbsp; try: &amp;nbsp;&amp;nbsp;&amp;nbsp; inTable = "Avg_Daily" &amp;nbsp;&amp;nbsp;&amp;nbsp; keyField = "STATION_ID" &amp;nbsp;&amp;nbsp;&amp;nbsp; inField = [["Avg_Daily.OBJECTID","OBJECTID",],["Avg_Daily.STATION_ID","STATION_ID"], ["Avg_Daily.DLY_AVG", "DLY_AVG"]] &amp;nbsp;&amp;nbsp;&amp;nbsp; whereClause = "\"STATION_ID\" = 'CAP', 'DDM'" &amp;nbsp;&amp;nbsp;&amp;nbsp; outTable = "Test" &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeQueryTable_management(inTable,&amp;nbsp; outTable, "USE_KEY_FIELDS", keyField, inField, whereClause)&amp;nbsp; except Exception, e: &amp;nbsp;&amp;nbsp;&amp;nbsp; # If an error occurred, print line number and error message &amp;nbsp;&amp;nbsp;&amp;nbsp; import traceback, sys &amp;nbsp;&amp;nbsp;&amp;nbsp; tb = sys.exc_info()[2] &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Line %i" % tb.tb_lineno &amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Apr 2014 16:49:05 GMT</pubDate>
    <dc:creator>RameshGautam</dc:creator>
    <dc:date>2014-04-16T16:49:05Z</dc:date>
    <item>
      <title>MakeQueryTable_Management</title>
      <link>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313906#M24389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to create a table called "Test" from inputTable called "Avg_Daily" using arcpy.MakeQueryTable_Management option of arcpy. However, I am getting error which says "Error 999999: An Invalid SQL statement was used". I don't know where I used invalid SQL statement. Any idea? Here is the code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy from arcpy import env&amp;nbsp; env.workspace ="C:/RG/Projects/CriticalDataNetwork/CDEC.gdb"&amp;nbsp; try: &amp;nbsp;&amp;nbsp;&amp;nbsp; inTable = "Avg_Daily" &amp;nbsp;&amp;nbsp;&amp;nbsp; keyField = "STATION_ID" &amp;nbsp;&amp;nbsp;&amp;nbsp; inField = [["Avg_Daily.OBJECTID","OBJECTID",],["Avg_Daily.STATION_ID","STATION_ID"], ["Avg_Daily.DLY_AVG", "DLY_AVG"]] &amp;nbsp;&amp;nbsp;&amp;nbsp; whereClause = "\"STATION_ID\" = 'CAP', 'DDM'" &amp;nbsp;&amp;nbsp;&amp;nbsp; outTable = "Test" &amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeQueryTable_management(inTable,&amp;nbsp; outTable, "USE_KEY_FIELDS", keyField, inField, whereClause)&amp;nbsp; except Exception, e: &amp;nbsp;&amp;nbsp;&amp;nbsp; # If an error occurred, print line number and error message &amp;nbsp;&amp;nbsp;&amp;nbsp; import traceback, sys &amp;nbsp;&amp;nbsp;&amp;nbsp; tb = sys.exc_info()[2] &amp;nbsp;&amp;nbsp;&amp;nbsp; print "Line %i" % tb.tb_lineno &amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 16:49:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313906#M24389</guid>
      <dc:creator>RameshGautam</dc:creator>
      <dc:date>2014-04-16T16:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: MakeQueryTable_Management</title>
      <link>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313907#M24390</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;whereClause = "\"STATION_ID\" = 'CAP', 'DDM'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So you want to select if station id is CAP or DDM?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm not sure you can comma separate those it might need to be&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;whereClause = "\"STATION_ID\" = 'CAP' OR "\"STATION_ID\"=&amp;nbsp; 'DDM'"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;See if that works&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 17:18:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313907#M24390</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-04-16T17:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: MakeQueryTable_Management</title>
      <link>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313908#M24391</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;whereClause = "\"STATION_ID\" = 'CAP', 'DDM'"&lt;BR /&gt; &lt;BR /&gt;So you want to select if station id is CAP or DDM?&lt;BR /&gt;&lt;BR /&gt;I'm not sure you can comma separate those it might need to be&lt;BR /&gt;&lt;BR /&gt;whereClause = "\"STATION_ID\" = 'CAP' OR "\"STATION_ID\"=&amp;nbsp; 'DDM'"&lt;BR /&gt;&lt;BR /&gt;See if that works&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Or try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;whereClause = "\"STATION_ID\" IN ('CAP', 'DDM')"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 17:37:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313908#M24391</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-04-16T17:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: MakeQueryTable_Management</title>
      <link>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313909#M24392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Or try:&lt;BR /&gt;&lt;BR /&gt;whereClause = "\"STATION_ID\" IN ('CAP', 'DDM')"&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Now, the code runs without any problem, however, I can't see the output file. Any clue?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 22:05:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313909#M24392</guid>
      <dc:creator>RameshGautam</dc:creator>
      <dc:date>2014-04-16T22:05:51Z</dc:date>
    </item>
    <item>
      <title>Re: MakeQueryTable_Management</title>
      <link>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313910#M24393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Now, the code runs without any problem, however, I can't see the output file. Any clue?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Your output "Test" table is merely a query table which is stored in memory and not something that is physically written somewhere.&amp;nbsp; If you want to write your "Test" table out to disk, use the &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.2/index.html#//001200000026000000" rel="nofollow" target="_blank"&gt;Table To Geodatabase (Conversion)&lt;/A&gt;&lt;SPAN&gt; tool and convert the table from being in memory to your workspace:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.TableToGeodatabase_conversion(outTable, "C:/RG/Projects/CriticalDataNetwork/CDEC.gdb")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 23:42:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313910#M24393</guid>
      <dc:creator>WilliamCraft</dc:creator>
      <dc:date>2014-04-16T23:42:29Z</dc:date>
    </item>
    <item>
      <title>Re: MakeQueryTable_Management</title>
      <link>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313911#M24394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Really, the MakeQueryTable tool is geared around doing complex queries with multiple related tables.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you just want to extract some records to a new on-disk table use the Select_analysis tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to make a in-memory pointer to some particular records in a table (aka 'a view') use the MakeTableView tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.Select_analysis(myInputTblPath, myOutputTblPath, "STATION_ID in ('CAP','DDM')")
#or
arcpy.MakeTableView_management(myInputTblPath, "my_table_view", "STATION_ID in ('CAP','DDM')")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;BTW: Per my undersatnding, a QueryTable and TableView (and a FeatureLayer as well) do not store the actual records of the table in memory (aka the RAM). Rather they store references to the on-disk records. Basically it builds a hash table of the key fields that satisfy a particular SQL query. Only the keys and their relationships are stored in RAM.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:58:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313911#M24394</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T14:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: MakeQueryTable_Management</title>
      <link>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313912#M24395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you so much for the feedback. It is great to know the secrets behind the query table tool.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Really, the MakeQueryTable tool is geared around doing complex queries with multiple related tables.&lt;BR /&gt;&lt;BR /&gt;If you just want to extract some records to a new on-disk table use the Select_analysis tool.&lt;BR /&gt;&lt;BR /&gt;If you want to make a in-memory pointer to some particular records in a table (aka 'a view') use the MakeTableView tool.&lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.Select_analysis(myInputTblPath, myOutputTblPath, "STATION_ID in ('CAP','DDM')")
#or
arcpy.MakeTableView_management(myInputTblPath, "my_table_view", "STATION_ID in ('CAP','DDM')")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;BTW: Per my undersatnding, a QueryTable and TableView (and a FeatureLayer as well) do not store the actual records of the table in memory (aka the RAM). Rather they store references to the on-disk records. Basically it builds a hash table of the key fields that satisfy a particular SQL query. Only the keys and their relationships are stored in RAM.&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:58:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313912#M24395</guid>
      <dc:creator>RameshGautam</dc:creator>
      <dc:date>2021-12-11T14:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: MakeQueryTable_Management</title>
      <link>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313913#M24396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Why am I getting an Invalid sQL Statement error in this code? where I, simply would like to pull the data from OLE DB connection.&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

try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; inTable = ["Database Connections/OLE DB Connection.odc/ORADBA.COUNTY"]
&amp;nbsp;&amp;nbsp;&amp;nbsp; inField = [["ORADBA.COUNTY.OBJECTID", 'OBJECTID'], ["ORADBA.COUNTY.COUNTY_NUM", 'COUNTY_NUM'],\
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ["ORADBA.COUNTY.COUNTY_NAME", 'COUNTY_NAME']]
&amp;nbsp;&amp;nbsp;&amp;nbsp; keyField = "ORADBA.COUNTY.OBJECTID"
&amp;nbsp;&amp;nbsp;&amp;nbsp; whereClause = "\"ORADBA.COUNTY.COUNTY_NAME\" = 'ORADBA.COUNTY.KINGS'"

&amp;nbsp;&amp;nbsp;&amp;nbsp; outTable = "C:/RG/Projects/CriticalDataNetwork/CDEC/Kings"
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeQueryTable_management(inTable, outTable, "USE_KEY_FIELDS", keyField, inField, whereClause)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.TableToGeodatabase_conversion(outTable, "C:/RG/Projects/CriticalDataNetwork/CDEC.gdb")
except Exception, e:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # If an error occurred, print line number and error message
&amp;nbsp;&amp;nbsp;&amp;nbsp; import traceback, sys
&amp;nbsp;&amp;nbsp;&amp;nbsp; tb = sys.exc_info()[2]
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Line %i" % tb.tb_lineno
&amp;nbsp;&amp;nbsp;&amp;nbsp; print e.message&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:58:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313913#M24396</guid>
      <dc:creator>RameshGautam</dc:creator>
      <dc:date>2021-12-11T14:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: MakeQueryTable_Management</title>
      <link>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313914#M24397</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;What is that where clause doing?&amp;nbsp; It seems unlikely you have a field with a user entered string value that looks anything like what you typed.&amp;nbsp; I would think that these are two fields being matched up, in which case the second half of the expression would not be quoted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Using fully qualified field names can be tricky.&amp;nbsp; Sometimes you don't need to use them.&amp;nbsp; I always test broken expressions in ModelBuilder or Desktop query builder and paste that into Python scripts once the bugs are out.&amp;nbsp; I never freehand type a complex field name or expression for fear of some nearly invisible typo sneaking in.&amp;nbsp; Too much time can be wasted hunting for a misplaced period.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Apr 2014 21:06:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/makequerytable-management/m-p/313914#M24397</guid>
      <dc:creator>RichardFairhurst</dc:creator>
      <dc:date>2014-04-17T21:06:37Z</dc:date>
    </item>
  </channel>
</rss>

