on 2014 Sep 02 2:54 PM
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?
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
Request clarification before answering.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Elmi, thanks for your comment,
User | Count |
---|---|
76 | |
30 | |
10 | |
8 | |
8 | |
7 | |
7 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.