<?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>Question Re: Significant difference between SQL/Anywhere and MS SQL/Server - CURSOR variable evaluation in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/significant-difference-between-sql-anywhere-and-ms-sql-server-cursor/qaa-p/13844454#M4875297</link>
    <description>&lt;P&gt;The term "cursor variable" has a meaning quite distinct from "parameter" which is what @parm1 is. See the section "Using the cursor Variable" in &lt;A href="http://technet.microsoft.com/en-us/library/ms190028(v=sql.105).aspx"&gt;Transact-SQL Cursors&lt;/A&gt;.&lt;/P&gt;</description>
    <pubDate>Tue, 02 Sep 2014 20:58:51 GMT</pubDate>
    <dc:creator>Breck_Carter</dc:creator>
    <dc:date>2014-09-02T20:58:51Z</dc:date>
    <item>
      <title>Significant difference between SQL/Anywhere and MS SQL/Server - CURSOR variable evaluation</title>
      <link>https://community.sap.com/t5/technology-q-a/significant-difference-between-sql-anywhere-and-ms-sql-server-cursor/qaq-p/13844451</link>
      <description>&lt;P&gt;This may be a documentation or standards concern, but the function below demonstrates very different results between SQL/Anywhere (12.0.0) and MS SQL/Server (2008 R2). On SQL/Anywhere, this function always returns 2, but on SQL/Server, it returns the value of the parameter passed in. In other words, the return value hinges on when @parm1 is evaluated: for SQL/Anywhere, it's at the OPEN, for SQL/Server, it's at the DECLARE. Microsoft documents this as "Variables may be used as part of the select_statement that declares a cursor. Cursor variable values do not change after a cursor is declared. In SQL Server version 6.5 and earlier, variable values are refreshed every time a cursor is reopened." I didn't see this mentioned in the SQL/Anywhere documentation, though I didn't look too hard - is it an SQL/92 vs SQL/2008 standards discrepancy?&lt;/P&gt;
&lt;PRE class="codehilite"&gt;&lt;CODE&gt;ALTER FUNCTION fncursorTest( @parm1 INTEGER )
RETURNS INTEGER
AS
BEGIN
    DECLARE @retval INTEGER;
    DECLARE cursor1 CURSOR FOR
        SELECT @parm1;
    SET @parm1 = 2;
    OPEN cursor1;
    FETCH cursor1 INTO @retval;
    CLOSE cursor1;
    DEALLOCATE cursor1;
    RETURN @retval;
END&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Sep 2014 13:54:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/significant-difference-between-sql-anywhere-and-ms-sql-server-cursor/qaq-p/13844451</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-09-02T13:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Significant difference between SQL/Anywhere and MS SQL/Server - CURSOR variable evaluation</title>
      <link>https://community.sap.com/t5/technology-q-a/significant-difference-between-sql-anywhere-and-ms-sql-server-cursor/qaa-p/13844452#M4875295</link>
      <description>&lt;P&gt;In SQL Anywhere, a variable used in a query is evaluated no earlier than at the cursor OPEN time, and possibly as late as FETCH time.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2014 15:34:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/significant-difference-between-sql-anywhere-and-ms-sql-server-cursor/qaa-p/13844452#M4875295</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-09-02T15:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Significant difference between SQL/Anywhere and MS SQL/Server - CURSOR variable evaluation</title>
      <link>https://community.sap.com/t5/technology-q-a/significant-difference-between-sql-anywhere-and-ms-sql-server-cursor/qaa-p/13844453#M4875296</link>
      <description>&lt;P&gt;Elmi, thanks for your comment,&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Do you know if this is described in the SQL Anywhere documentation somewhere (it's not mentioned in the "SQL dialects and compatibility" / "SQL Anywhere features that differ from other SQL implementations" section. Is this compatible with Adaptive Server Enterprise?)&lt;/LI&gt;
&lt;LI&gt;Does this conform to SQL/2008 or is the standard too vague on the issue?&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 02 Sep 2014 16:23:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/significant-difference-between-sql-anywhere-and-ms-sql-server-cursor/qaa-p/13844453#M4875296</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-09-02T16:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: Significant difference between SQL/Anywhere and MS SQL/Server - CURSOR variable evaluation</title>
      <link>https://community.sap.com/t5/technology-q-a/significant-difference-between-sql-anywhere-and-ms-sql-server-cursor/qaa-p/13844454#M4875297</link>
      <description>&lt;P&gt;The term "cursor variable" has a meaning quite distinct from "parameter" which is what @parm1 is. See the section "Using the cursor Variable" in &lt;A href="http://technet.microsoft.com/en-us/library/ms190028(v=sql.105).aspx"&gt;Transact-SQL Cursors&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Sep 2014 20:58:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/significant-difference-between-sql-anywhere-and-ms-sql-server-cursor/qaa-p/13844454#M4875297</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2014-09-02T20:58:51Z</dc:date>
    </item>
    <item>
      <title>Re: Significant difference between SQL/Anywhere and MS SQL/Server - CURSOR variable evaluation</title>
      <link>https://community.sap.com/t5/technology-q-a/significant-difference-between-sql-anywhere-and-ms-sql-server-cursor/qaa-p/13844455#M4875298</link>
      <description>&lt;OL&gt;
&lt;LI&gt;As far as I can tell, there is no description of the behaviour in the SQL Anywhere documentation.&lt;/LI&gt;
&lt;LI&gt;SQL/2011 standard, Foundation, Section 15.1, General Rules 5)a
)i) implies that all variables used in a cursor are evaluated at OPEN time.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 03 Sep 2014 11:07:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/significant-difference-between-sql-anywhere-and-ms-sql-server-cursor/qaa-p/13844455#M4875298</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-09-03T11:07:37Z</dc:date>
    </item>
  </channel>
</rss>

