<?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: How can I access a SQL Server 2012 database sequence value in arcpy  in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396332#M31286</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Convert doesn't seem to work either.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Jim&lt;IMG alt="Capture2.JPG" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/211738_Capture2.JPG" style="width: 620px; height: 310px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 13 Jul 2016 20:56:05 GMT</pubDate>
    <dc:creator>JamesFox1</dc:creator>
    <dc:date>2016-07-13T20:56:05Z</dc:date>
    <item>
      <title>How can I access a SQL Server 2012 database sequence value in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396327#M31281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had python script tool that accessed a sequence value and got the&lt;/P&gt;&lt;P&gt;value via arcpy.ArcSDESQLExecute call. We are porting our SDE environment&lt;/P&gt;&lt;P&gt;from Oracle 11g to SQL Server 2012 and as such changed the sequence select &lt;/P&gt;&lt;P&gt;from ALL_SEQUENCES to sys.sequences as shown:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select_list = '&lt;STRONG&gt;SELECT DISTINCT current_value&lt;/STRONG&gt; ' #&amp;nbsp; SELECT LAST_NUMBER '&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from_clause = '&lt;STRONG&gt;FROM sys.sequences&lt;/STRONG&gt; ' # ' FROM ALL_SEQUENCES '&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where_clause = '&lt;STRONG&gt;WHERE NAME = \''+seq_name+'\&lt;/STRONG&gt;' ' # 'WHERE SEQUENCE_OWNER = \'' + schema + '\' AND SEQUENCE_NAME&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This SQL works in SSMS or SQL_CMD but not in arcpy (it did work correctly in Oracle 11g)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;is there now an arcpy call that will get a sequence value (CURRVAL) directly without &lt;/P&gt;&lt;P&gt;building SQL and using ArcSDESQLExecute?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Jim&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Jul 2016 22:46:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396327#M31281</guid>
      <dc:creator>JamesFox1</dc:creator>
      <dc:date>2016-07-12T22:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: How can I access a SQL Server 2012 database sequence value in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396328#M31282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are you receiving any kind of error from &lt;SPAN style="font-family: courier new,courier;"&gt;arcpy.ArcSDESQLExecute&lt;/SPAN&gt; ?&amp;nbsp; Looking in SQL Server just now, I notice that &lt;SPAN style="font-family: courier new,courier;"&gt;current_value&lt;/SPAN&gt; is type &lt;SPAN style="font-family: courier new,courier;"&gt;sql_variant&lt;/SPAN&gt;.&amp;nbsp; Have you tried casting the value to see if this is a data type mismatch or unsupported data type?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jul 2016 01:11:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396328#M31282</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2016-07-13T01:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: How can I access a SQL Server 2012 database sequence value in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396329#M31283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm already casting the value:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try:&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; &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; sde_return = connection.execute(sql_txt)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # If the return value is a list (a list of lists), display&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # each list as a row from the table being queried.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seq_val = &lt;STRONG&gt;int(sde_return)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Should it be done earlier?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jul 2016 16:00:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396329#M31283</guid>
      <dc:creator>JamesFox1</dc:creator>
      <dc:date>2016-07-13T16:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: How can I access a SQL Server 2012 database sequence value in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396330#M31284</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes.&amp;nbsp; Trying casting within the SQL itself so that a compatible SQL data type is being returned to &lt;SPAN style="font-family: courier new,courier;"&gt;arcpy.ArcSDESQLExecute&lt;/SPAN&gt; by the DBMS.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jul 2016 16:41:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396330#M31284</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2016-07-13T16:41:05Z</dc:date>
    </item>
    <item>
      <title>Re: How can I access a SQL Server 2012 database sequence value in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396331#M31285</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Josh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried casting in the sql as integer, int, bigint, smallint and tinyint - no luck. The code is pulling and using as python integer type.&lt;IMG alt="Capture.JPG" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/211734_Capture.JPG" style="width: 620px; height: 391px;" /&gt;&lt;IMG alt="Capture1.JPG" class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/211735_Capture1.JPG" style="width: 620px; height: 422px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Jim&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jul 2016 19:22:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396331#M31285</guid>
      <dc:creator>JamesFox1</dc:creator>
      <dc:date>2016-07-13T19:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can I access a SQL Server 2012 database sequence value in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396332#M31286</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Convert doesn't seem to work either.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Jim&lt;IMG alt="Capture2.JPG" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/211738_Capture2.JPG" style="width: 620px; height: 310px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jul 2016 20:56:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396332#M31286</guid>
      <dc:creator>JamesFox1</dc:creator>
      <dc:date>2016-07-13T20:56:05Z</dc:date>
    </item>
    <item>
      <title>Re: How can I access a SQL Server 2012 database sequence value in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396333#M31287</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;wrapping in T-SQL function?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jul 2016 14:42:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396333#M31287</guid>
      <dc:creator>JamesFox1</dc:creator>
      <dc:date>2016-07-14T14:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: How can I access a SQL Server 2012 database sequence value in arcpy</title>
      <link>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396334#M31288</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;After doing a bit of testing and looking at your code, I am wondering whether your SQL is generating an error, which is then having &lt;SPAN style="font-family: courier new,courier;"&gt;sde_return&lt;/SPAN&gt; get set to &lt;SPAN style="font-family: courier new,courier;"&gt;False&lt;/SPAN&gt;, and &lt;SPAN style="font-family: courier new,courier;"&gt;False&lt;/SPAN&gt; is getting cast to 0.&amp;nbsp; What if you call &lt;SPAN style="font-family: courier new,courier;"&gt;arcpy.ArcSDESQLExecute&lt;/SPAN&gt; outside of the &lt;SPAN style="font-family: courier new,courier;"&gt;try&lt;/SPAN&gt; statement, what do you get?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For me, I have to cast current_value in SQL in order to avoid generating an error:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; sde_file = # path to SDE connection file
&amp;gt;&amp;gt;&amp;gt; sde_conn = arcpy.ArcSDESQLExecute(sde_file)
&amp;gt;&amp;gt;&amp;gt; # Run SQL without casting
&amp;gt;&amp;gt;&amp;gt; sql_nocast = "SELECT current_value FROM sys.sequences WHERE name = 'CountBy1'"
&amp;gt;&amp;gt;&amp;gt; sde_conn.execute(sql_nocast)
Runtime error 
Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\arcobjects\arcobjects.py", line 27, in execute
&amp;nbsp;&amp;nbsp;&amp;nbsp; return convertArcObjectToPythonObject(self._arc_object.Execute(*gp_fixargs(args)))
AttributeError: ArcSDESQLExecute: StreamBindOutputColumn ArcSDE Error -65 \ue45c
&amp;gt;&amp;gt;&amp;gt; 
&amp;gt;&amp;gt;&amp;gt; # Run SQL with casting
&amp;gt;&amp;gt;&amp;gt; sql_cast = "SELECT CAST(current_value AS INT) FROM sys.sequences WHERE name = 'CountBy1'"
&amp;gt;&amp;gt;&amp;gt; sde_conn.execute(sql_cast)
1
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:07:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-can-i-access-a-sql-server-2012-database/m-p/396334#M31288</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T18:07:51Z</dc:date>
    </item>
  </channel>
</rss>

