<?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: Compare GUID type field to Identical GUID string in SQL Where Query in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/compare-guid-type-field-to-identical-guid-string/m-p/1033048#M60206</link>
    <description>&lt;P&gt;Perfect, thanks!!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Mar 2021 19:35:28 GMT</pubDate>
    <dc:creator>LeviCecil</dc:creator>
    <dc:date>2021-03-04T19:35:28Z</dc:date>
    <item>
      <title>Compare GUID type field to Identical GUID string in SQL Where Query</title>
      <link>https://community.esri.com/t5/python-questions/compare-guid-type-field-to-identical-guid-string/m-p/1033022#M60201</link>
      <description>&lt;P&gt;I have a Python script that exports sde attachments, photos submitted through Survey123. I need to rename the resulting JPGs with the site, room and time they were taken. The initial file name only has the relative global ID from the attachment table that relates to the global ID of the room feature in the survey table. Comparing these is how I get the room data for renaming the JPG file. It works just fine, but we have nearly 15,000 rooms over 100 sites, so I want to speed up the cursor search with a SQL query.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is, the Global ID field from the survey table is a GUID type field. The identical relative global ID field in the attachment table is a string. The Global ID field is only cast to string inside the cursor GUID = item[0]. The SQL where clause is defined outside the cursor, where Global ID refers to the GUID type field. I've tried&amp;nbsp;&lt;FONT color="#000000"&gt;converting the relative ID string field to a UUID type, but this hasn't worked. I tried setting the where clause as an empty string and then defining it inside the search cursor loop.&amp;nbsp;&lt;/FONT&gt;I keep getting this error:&amp;nbsp; &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;for item in cursor:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;RuntimeError: Underlying DBMS error [[Microsoft][ODBC Driver 13 for SQL Server]Syntax error, permission violation, or other nonspecific error] [PPSTest.DBO.CustodianInspection]&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Here is the relative section of my script:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;##Step 2 -Loop through each photo and get time taken from metadata
        
for jpg in os.listdir(temp_dir):

    filepath = temp_dir + "//" + jpg
  
    date_time = (get_date_taken(filepath))
    date_time_obj = datetime.datetime.strptime(date_time, '%Y:%m:%d %H:%M:%S')
    date_string = date_time_obj.strftime("%b %d %Y")
    time_string = date_time_obj.strftime("%I_%M_%S%p")
    REL_GUID = jpg[5:43]

    ##Step 3 -Compare REL_GUID in photo filename to GUID in custodian inspection table to grab site name and room number
    
    where_clause = "WHERE GlobalID  = " + REL_GUID
    
    with da.SearchCursor(inspection_table, ['GlobalID', 'SiteName', 'RoomNumber','Comments','appa_score'],where_clause) as cursor:

                for item in cursor:
                    
                    GUID = item[0]
                    SiteName = item[1]
                    RoomNum = item[2]
                    comments = item[3]
                    appaScore = str(item[4])
                   &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 19:11:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-guid-type-field-to-identical-guid-string/m-p/1033022#M60201</guid>
      <dc:creator>LeviCecil</dc:creator>
      <dc:date>2021-03-04T19:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Compare GUID type field to Identical GUID string in SQL Where Query</title>
      <link>https://community.esri.com/t5/python-questions/compare-guid-type-field-to-identical-guid-string/m-p/1033043#M60205</link>
      <description>&lt;P&gt;strings need to be surrounded by ' for sql.&lt;/P&gt;&lt;P&gt;try&lt;/P&gt;&lt;LI-CODE lang="python"&gt;where_clause = """WHERE GlobalID  = '{}'""".format(REL_GUID)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 19:25:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-guid-type-field-to-identical-guid-string/m-p/1033043#M60205</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-03-04T19:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: Compare GUID type field to Identical GUID string in SQL Where Query</title>
      <link>https://community.esri.com/t5/python-questions/compare-guid-type-field-to-identical-guid-string/m-p/1033048#M60206</link>
      <description>&lt;P&gt;Perfect, thanks!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Mar 2021 19:35:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/compare-guid-type-field-to-identical-guid-string/m-p/1033048#M60206</guid>
      <dc:creator>LeviCecil</dc:creator>
      <dc:date>2021-03-04T19:35:28Z</dc:date>
    </item>
  </channel>
</rss>

