<?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: Getting Error in arcpy using Cursor in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087600#M62009</link>
    <description>&lt;P&gt;Sir, See if i have ranges for the date like from 1935-2035 so below statement is correct? Actually while printing the below statement it's only giving me the upper value i.e.,&amp;nbsp;('2035-01-01', '%Y-%m-%d')&lt;/P&gt;&lt;P&gt;INSTALLATIONDATE = datetime.strptime("1935-01-01" , "%Y-%m-%d") and ("2035-01-01" , "%Y-%m-%d")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also what will be the "Where Clause" for the same as per you?&lt;/P&gt;</description>
    <pubDate>Tue, 10 Aug 2021 18:15:25 GMT</pubDate>
    <dc:creator>broy06</dc:creator>
    <dc:date>2021-08-10T18:15:25Z</dc:date>
    <item>
      <title>Getting Error in arcpy using Cursor</title>
      <link>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087363#M61999</link>
      <description>&lt;P&gt;Hello everyone, I am getting error while printing the "INSTALLATIONDATE" &amp;amp; "MEASUREDLENGTH". MEASUREDLENGTH is having double datatype &amp;amp;&amp;nbsp;INSTALLATIONDATE is having date data type. Could you please check my complete code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my code:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&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; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; arcpy
     &lt;SPAN class="hljs-keyword"&gt;from&lt;/SPAN&gt; datetime &lt;SPAN class="hljs-keyword"&gt;import&lt;/SPAN&gt; datetime
     arcpy.env.workspace = &lt;SPAN class="hljs-string"&gt;"D:\Pipe\map.gdb"&lt;/SPAN&gt;
     featureClass_1 = &lt;SPAN class="hljs-string"&gt;"P_Pipes"&lt;/SPAN&gt;
     Table_Pipe = &lt;SPAN class="hljs-string"&gt;"Pipe_Risk"&lt;/SPAN&gt;
     fieldNames_1 = [ &lt;SPAN class="hljs-string"&gt;"Material"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"OPERATINGPRESSURE"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"MEASUREDLENGTH"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"INSTALLATIONDATE"&lt;/SPAN&gt;, &lt;SPAN class="hljs-string"&gt;"Risk_Score"&lt;/SPAN&gt;]
     fieldNames = [&lt;SPAN class="hljs-string"&gt;"Material"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"OPERATINGPRESSURE"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"MEASUREDLENGTHLOWERLIMIT"&lt;/SPAN&gt; ,&lt;SPAN class="hljs-string"&gt;"MEASUREDLENGTHUPPERLIMIT"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"INSTALLATIONDATELOWERLIMIT"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"INSTALLATIONDATEUPPERLIMIT"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"OVERALLRISKSCORE"&lt;/SPAN&gt;] #Lookup table



     &lt;SPAN class="hljs-keyword"&gt;def&lt;/SPAN&gt; &lt;SPAN class="hljs-title function_"&gt;Pipe_Risk_Score&lt;/SPAN&gt;(&lt;SPAN class="hljs-params"&gt;Material, OPERATINGPRESSURE, MEASUREDLENGTH, INSTALLATIONDATE):&lt;/SPAN&gt;&lt;/PRE&gt;&lt;H1&gt;Case: Material&lt;/H1&gt;&lt;PRE&gt;    &lt;SPAN class="hljs-comment"&gt;#Material_Out_fields = ["Material" , "OVERALLRISKSCORE"]&lt;/SPAN&gt;

    Material_where_Clause = &lt;SPAN class="hljs-string"&gt;"Material = "&lt;/SPAN&gt; + Material
    Table_Pipe_Cursor = arcpy.da.SearchCursor(Table_Pipe, [&lt;SPAN class="hljs-string"&gt;"Material"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"OVERALLRISKSCORE"&lt;/SPAN&gt;],Material_where_Clause)
    &lt;SPAN class="hljs-keyword"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="hljs-keyword"&gt;in&lt;/SPAN&gt; Table_Pipe_Cursor:

        Material_Risk_Score = row[&lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt;]
        &lt;SPAN class="hljs-built_in"&gt;print&lt;/SPAN&gt; Material_Risk_Score&lt;/PRE&gt;&lt;H1&gt;Case: Operating Pressure&lt;/H1&gt;&lt;PRE&gt;    OP_Out_fields = [&lt;SPAN class="hljs-string"&gt;"OPERATINGPRESSURE"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"OVERALLRISKSCORE"&lt;/SPAN&gt;]
    OP_where_Clause = &lt;SPAN class="hljs-string"&gt;"OPERATINGPRESSURE = "&lt;/SPAN&gt; + OPERATINGPRESSURE
    Table_Pipe_Cursor = arcpy.da.SearchCursor(Table_Pipe, OP_Out_fields, OP_where_Clause)

    &lt;SPAN class="hljs-keyword"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="hljs-keyword"&gt;in&lt;/SPAN&gt; Table_Pipe_Cursor:

        OPERATINGPRESSURE_Risk_Score = row[&lt;SPAN class="hljs-number"&gt;1&lt;/SPAN&gt;]
        &lt;SPAN class="hljs-built_in"&gt;print&lt;/SPAN&gt; (OPERATINGPRESSURE_Risk_Score)&lt;/PRE&gt;&lt;H1&gt;Case: ML&lt;/H1&gt;&lt;PRE&gt;    ML_Out_fields = [&lt;SPAN class="hljs-string"&gt;"MEASUREDLENGTHLOWERLIMIT"&lt;/SPAN&gt; ,&lt;SPAN class="hljs-string"&gt;"MEASUREDLENGTHUPPERLIMIT"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"OVERALLRISKSCORE"&lt;/SPAN&gt;]
    ML_where_Clause = &lt;SPAN class="hljs-string"&gt;"MEASUREDLENGTHLOWERLIMIT &amp;lt;= "&lt;/SPAN&gt; + MEASUREDLENGTH + &lt;SPAN class="hljs-string"&gt;" and MEASUREDLENGTHUPPERLIMIT &amp;gt;= "&lt;/SPAN&gt; + MEASUREDLENGTH 
    &lt;SPAN class="hljs-built_in"&gt;print&lt;/SPAN&gt; ML_where_Clause

#Not giving me output after Print (ML_where_Clause)
    Table_Pipe_Cursor = arcpy.da.SearchCursor(Table_Pipe, ML_Out_fields, ML_where_Clause)

    &lt;SPAN class="hljs-keyword"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="hljs-keyword"&gt;in&lt;/SPAN&gt; Table_Pipe_Cursor:

        MEASUREDLENGTH_Risk_Score = row[&lt;SPAN class="hljs-number"&gt;2&lt;/SPAN&gt;]
        &lt;SPAN class="hljs-built_in"&gt;print&lt;/SPAN&gt; MEASUREDLENGTH_Risk_Score #No output of this print function&lt;/PRE&gt;&lt;H1&gt;Case: ID&lt;/H1&gt;&lt;PRE&gt;    INSTALLATIONDATE = datetime.strptime(&lt;SPAN class="hljs-string"&gt;"1935-01-01 "&lt;/SPAN&gt; ,&lt;SPAN class="hljs-string"&gt;"%Y-%m-%d"&lt;/SPAN&gt;) &lt;SPAN class="hljs-comment"&gt;#"01/01/2035 00:00:00")&lt;/SPAN&gt;
    ID_Out_fields = [&lt;SPAN class="hljs-string"&gt;"INSTALLATIONDATELOWERLIMIT"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"INSTALLATIONDATEUPPERLIMIT"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"OVERALLRISKSCORE"&lt;/SPAN&gt;]
    ID_where_Clause = &lt;SPAN class="hljs-string"&gt;"INSTALLATIONDATELOWERLIMIT &amp;lt;= datetime(1935-01-01 ) and INSTALLATIONDATEUPPERLIMIT &amp;gt;= datetime(2035-01-01 )"&lt;/SPAN&gt;

    Table_Pipe_Cursor = arcpy.da.SearchCursor(Table_Pipe, ID_Out_fields, ID_where_Clause)
    &lt;SPAN class="hljs-keyword"&gt;for&lt;/SPAN&gt; row &lt;SPAN class="hljs-keyword"&gt;in&lt;/SPAN&gt; Table_Pipe_Cursor:

        ID_Risk_Score = row[&lt;SPAN class="hljs-number"&gt;2&lt;/SPAN&gt;]
        &lt;SPAN class="hljs-built_in"&gt;print&lt;/SPAN&gt; (ID_Risk_Score) # Error: Unconverted data remains:&lt;/PRE&gt;&lt;P&gt;#Final_Risk_Score = (Material_Risk_Score + OP_Risk_Score + ML_Risk_Score + ID_Risk_Score)/4&lt;/P&gt;&lt;P&gt;#Pipe_Risk_Score(Material , OPERATINGPRESSURE , MEASUREDLENGTH , INSTALLATIONDATE) # Showing me Name error using this line without quotes&lt;/P&gt;&lt;PRE&gt;   Pipe_Risk_Score(&lt;SPAN class="hljs-string"&gt;"Material"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"OPERATINGPRESSURE"&lt;/SPAN&gt; , &lt;SPAN class="hljs-string"&gt;"MEASUREDLENGTH",&amp;nbsp;"INSTALLATIONDATE")&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 09:54:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087363#M61999</guid>
      <dc:creator>broy06</dc:creator>
      <dc:date>2021-08-10T09:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Error in arcpy using Cursor</title>
      <link>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087542#M62003</link>
      <description>&lt;P&gt;For your text based where clauses, you'll need single quotes around the text value. For example:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Material_where_Clause = "Material = '{}'".format(Material)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The date expressions are failing because you have a trailing space.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;INSTALLATIONDATE = datetime.strptime("1935-01-01", "%Y-%m-%d")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 16:34:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087542#M62003</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-08-10T16:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Error in arcpy using Cursor</title>
      <link>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087600#M62009</link>
      <description>&lt;P&gt;Sir, See if i have ranges for the date like from 1935-2035 so below statement is correct? Actually while printing the below statement it's only giving me the upper value i.e.,&amp;nbsp;('2035-01-01', '%Y-%m-%d')&lt;/P&gt;&lt;P&gt;INSTALLATIONDATE = datetime.strptime("1935-01-01" , "%Y-%m-%d") and ("2035-01-01" , "%Y-%m-%d")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also what will be the "Where Clause" for the same as per you?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 18:15:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087600#M62009</guid>
      <dc:creator>broy06</dc:creator>
      <dc:date>2021-08-10T18:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Error in arcpy using Cursor</title>
      <link>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087613#M62011</link>
      <description>&lt;P&gt;The&lt;FONT face="courier new,courier" color="#000000"&gt; &amp;lt;= and &amp;gt;= &lt;/FONT&gt;you used in your original code should work for querying a date range. Just get rid of all trailing spaces.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 18:41:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087613#M62011</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-08-10T18:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Error in arcpy using Cursor</title>
      <link>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087619#M62013</link>
      <description>&lt;P&gt;Sir, so what will be my where clause? Could you please tell?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 18:46:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087619#M62013</guid>
      <dc:creator>broy06</dc:creator>
      <dc:date>2021-08-10T18:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Error in arcpy using Cursor</title>
      <link>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087625#M62014</link>
      <description>&lt;P&gt;I should have asked where your data is because that will change the syntax a little.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-questions/using-where-clause-to-query-date-ranges-in-arcpy/m-p/666904/highlight/true#M51795" target="_blank" rel="noopener"&gt;Re: Using where clause to query date ranges in Arc... - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;For example, a file geodatabase where clause with date would be&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;ID_where_Clause = "INSTALLATIONDATELOWERLIMIT &amp;gt;= date '1935-01-01' AND INSTALLATIONDATEUPPERLIMIT &amp;lt;= date '2035-01-01'"&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 19:00:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087625#M62014</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-08-10T19:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Error in arcpy using Cursor</title>
      <link>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087638#M62015</link>
      <description>&lt;P&gt;Sir, I'm using file gdb. But the code gives me error. Please get me rid out of this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the error statement in bold:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;for row in Table_Pipe_Cursor:&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;RuntimeError: An invalid SQL statement was used. [SELECT INSTALLATIONDATELOWERLIMIT, INSTALLATIONDATEUPPERLIMIT, OVERALLRISKSCORE, OBJECTID FROM Gas_Valve_Risk WHERE INSTALLATIONDATELOWERLIMIT &amp;lt;= datetime('1935-01-01') and INSTALLATIONDATEUPPERLIMIT &amp;gt;= datetime('2035-01-01')]&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PrabalTripathi_0-1628623356656.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/20570iBF6C18256C1D0E55/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PrabalTripathi_0-1628623356656.png" alt="PrabalTripathi_0-1628623356656.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 19:29:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087638#M62015</guid>
      <dc:creator>broy06</dc:creator>
      <dc:date>2021-08-10T19:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Getting Error in arcpy using Cursor</title>
      <link>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087663#M62018</link>
      <description>&lt;P&gt;You're using the wrong syntax for a file geodatabase.&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/mapping/navigation/sql-reference-for-elements-used-in-query-expressions.htm#GUID-85C03D85-F4A5-48FC-8E8C-3F79919430DB" target="_blank"&gt;SQL reference for query expressions used in ArcGIS—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Try&lt;/P&gt;&lt;P&gt;ID_where_Clause = "INSTALLATIONDATELOWERLIMIT &amp;gt;= date '1935-01-01' AND INSTALLATIONDATEUPPERLIMIT &amp;lt;= date '2035-01-01'"&lt;/P&gt;&lt;P&gt;If that doesn't work, try adding the time component like&lt;/P&gt;&lt;P&gt;ID_where_Clause = "INSTALLATIONDATELOWERLIMIT &amp;gt;= date '1935-01-01 00:00:00' AND INSTALLATIONDATEUPPERLIMIT &amp;lt;= date '2035-01-01 00:00:00'"&lt;/P&gt;</description>
      <pubDate>Tue, 10 Aug 2021 20:27:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/getting-error-in-arcpy-using-cursor/m-p/1087663#M62018</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-08-10T20:27:50Z</dc:date>
    </item>
  </channel>
</rss>

