<?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 Using WhereClause in your QueryDef to create a QueryTable in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/using-whereclause-in-your-querydef-to-create-a/m-p/1134766#M7629</link>
    <description>&lt;P&gt;Hi Everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use a list of keys, mukeys, to search for these mukey within the mukey field in the component table and create a query table, CompTable. I keep getting an error, field not found at the line, WhereClause within the QueryDef. How do I write the WhereClause&amp;nbsp; correctly using a the mukeys list? Here is my script below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;//there is more script above, but I just included the script section related to this question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;using (Row row = rowCursor.Current)&lt;BR /&gt;{&lt;BR /&gt;mukeyCount++;&lt;BR /&gt;var mukey = Convert.ToString(row["MUKEY"]);&lt;BR /&gt;mukeys.Add(mukey);&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;QueryDef queryDef = new QueryDef&lt;BR /&gt;{&lt;BR /&gt;Tables = "component",&lt;BR /&gt;WhereClause = "mukey= mukeys[mukeycount]",&amp;nbsp; //error occurs here&lt;BR /&gt;SubFields = "component.cokey,component.mukey,component.comppct_r"&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)&lt;BR /&gt;{&lt;BR /&gt;Name = "CompTable",&lt;BR /&gt;PrimaryKeys = geodatabase.GetSQLSyntax().QualifyColumnName("component", "cokey")&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;Table queryTable = geodatabase.OpenQueryTable(queryTableDescription);&lt;/P&gt;&lt;P&gt;Thanks everyone!&lt;/P&gt;</description>
    <pubDate>Tue, 18 Jan 2022 20:15:12 GMT</pubDate>
    <dc:creator>tzz_12</dc:creator>
    <dc:date>2022-01-18T20:15:12Z</dc:date>
    <item>
      <title>Using WhereClause in your QueryDef to create a QueryTable</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/using-whereclause-in-your-querydef-to-create-a/m-p/1134766#M7629</link>
      <description>&lt;P&gt;Hi Everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use a list of keys, mukeys, to search for these mukey within the mukey field in the component table and create a query table, CompTable. I keep getting an error, field not found at the line, WhereClause within the QueryDef. How do I write the WhereClause&amp;nbsp; correctly using a the mukeys list? Here is my script below:&amp;nbsp;&lt;/P&gt;&lt;P&gt;//there is more script above, but I just included the script section related to this question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;using (Row row = rowCursor.Current)&lt;BR /&gt;{&lt;BR /&gt;mukeyCount++;&lt;BR /&gt;var mukey = Convert.ToString(row["MUKEY"]);&lt;BR /&gt;mukeys.Add(mukey);&lt;BR /&gt;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;QueryDef queryDef = new QueryDef&lt;BR /&gt;{&lt;BR /&gt;Tables = "component",&lt;BR /&gt;WhereClause = "mukey= mukeys[mukeycount]",&amp;nbsp; //error occurs here&lt;BR /&gt;SubFields = "component.cokey,component.mukey,component.comppct_r"&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)&lt;BR /&gt;{&lt;BR /&gt;Name = "CompTable",&lt;BR /&gt;PrimaryKeys = geodatabase.GetSQLSyntax().QualifyColumnName("component", "cokey")&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;Table queryTable = geodatabase.OpenQueryTable(queryTableDescription);&lt;/P&gt;&lt;P&gt;Thanks everyone!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 20:15:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/using-whereclause-in-your-querydef-to-create-a/m-p/1134766#M7629</guid>
      <dc:creator>tzz_12</dc:creator>
      <dc:date>2022-01-18T20:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using WhereClause in your QueryDef to create a QueryTable</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/using-whereclause-in-your-querydef-to-create-a/m-p/1135398#M7638</link>
      <description>&lt;BLOCKQUOTE&gt;WhereClause = "mukey= mukeys[mukeycount]",&amp;nbsp; //error occurs here&lt;/BLOCKQUOTE&gt;&lt;P&gt;Because the WhereClause is looking for the field name as&amp;nbsp;&lt;EM&gt;mukeys[mukeycount] &lt;/EM&gt;that is not available. I&amp;nbsp; am guessing that&amp;nbsp; you are trying to find a&amp;nbsp; field name in&amp;nbsp;&lt;EM&gt;mukeys[mukeycount]&amp;nbsp;&lt;/EM&gt;which can be fetched as:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;WhereClause = $"mukey= {mukeys[mukeycount]}"&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 20 Jan 2022 13:30:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/using-whereclause-in-your-querydef-to-create-a/m-p/1135398#M7638</guid>
      <dc:creator>Aashis</dc:creator>
      <dc:date>2022-01-20T13:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using WhereClause in your QueryDef to create a QueryTable</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/using-whereclause-in-your-querydef-to-create-a/m-p/1136882#M7674</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/221628"&gt;@Aashis&lt;/a&gt;&amp;nbsp; is correct your 'where' clause is not properly constructed.&amp;nbsp; I think your intend was to construct a where clause using the 'in' clause, for example:&lt;/P&gt;&lt;P&gt;mukey in (100, 101, 205)&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;The 'in' clause allows you to specify a list of possible matches.&amp;nbsp; Depending on the datatype of mukey you might have to surround the 'in' clause items in single quotes.&lt;/P&gt;&lt;P&gt;Here is a sample that worked for me:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected override void OnClick()
{
  var mukeys = new List&amp;lt;string&amp;gt;();
  mukeys.Add("Test 1");
  mukeys.Add("Test 3");
  var inClause = string.Join("','", mukeys.Select(i =&amp;gt; i.Replace("'", "''")));

  _ = QueuedTask.Run(() =&amp;gt;
  {
    QueryDef queryDef = new QueryDef
    {
      Tables = "testlines",
      WhereClause = $@"description in ('{inClause}')",
      SubFields = "objectid,description"
    };
    System.Diagnostics.Trace.WriteLine($@"Where: {queryDef.WhereClause}");
    var defaultGdb = new FileGeodatabaseConnectionPath(new Uri(CoreModule.CurrentProject.DefaultGeodatabasePath));
    using (Geodatabase geodatabase = new Geodatabase(defaultGdb))
    {
      QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)
      {
        Name = "testlines",
        PrimaryKeys = geodatabase.GetSQLSyntax().QualifyColumnName("testlines", "objectid")
      };
      using (var queryTable = geodatabase.OpenQueryTable(queryTableDescription))
      {
        using (var cursor = queryTable.Search ())
        {
          while (cursor.MoveNext())
          {
            using (var row = cursor.Current)
            {
              System.Diagnostics.Trace.WriteLine($@"Found: {row["objectid"]} {row["description"]}");
            }
          }
        }
      }
    }
  });
}&lt;/LI-CODE&gt;&lt;P&gt;The diagnostic output of this snippet looks like this:&lt;/P&gt;&lt;P&gt;Where: description in ('Test 1','Test 3')&lt;BR /&gt;Found: 9 Test 1&lt;BR /&gt;Found: 11 Test 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jan 2022 15:30:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/using-whereclause-in-your-querydef-to-create-a/m-p/1136882#M7674</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2022-01-25T15:30:01Z</dc:date>
    </item>
  </channel>
</rss>

