Re: Possible Bug with TOP N clause in cursor definition. Re: Critical difference between behaviour of @@sqlstatus vs. MS-SQL @@FETCH_STATUS?!?
- From: David Kerber <ns_dkerber@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 14 Jun 2006 16:15:09 -0400
Have you tried putting an ORDER BY clause in your query? That would
ensure that you get the same 10 all the time...
In article <1150315392.293501.280740@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
emarinko@xxxxxxxxx says...
Here is some further detail about the problem I reported (see quoted
message). It seems to be a bug with the TOP N clause in the select
statement for the cursor definition.
With respect to the example below, I tried inserting the top 10
records into another table and running a cursor against that.
I noticed that if my query in the cursor definition is:
select strName from myTable
\----> Then I get 10 print statements in my cursor. (i.e. all the
expected rows).
However, if I change my query to:
select TOP 10 strName from myTable
\----> Then I only get 9 print statements out of my cursor. (last row
in result is missing).
One should expect the same result from both cases, but Sybase is not
consistent.
Riko wrote:
Hi,
That would skip the first row instead of the last row.
The first row is already fetched outside of the loop (otherwise could
never enter the loop because @@sqlstatus wouldn't be set to 0).
Then the second fetch would move to the second row before the first
print.
My concern is that my code follows the standard pattern in most
examples, including this one:
http://manuals.sybase.com/onlinebooks/group-as/asg1250e/sqlug/@Generic__BookTextView/51747;pt=51652;lang=zh?DwebQuery=@@sqlstatus
In that case, I get no message for the last title in the result set.
David Kerber wrote:
In article <1150306713.678794.59480@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
emarinko@xxxxxxxxx says...
...
DECLARE RC CURSOR FOR
select top 10 strName from tblCustomer
DECLARE @strName varchar(50)
OPEN RC
FETCH RC INTO @strName
WHILE @@sqlstatus=0
BEGIN
print @strName
FETCH RC INTO @strName
END
I use ASA rather than ASE so I may be off base here, but try swapping
the order of the lines inside your loop, so you fetch before printing.
...
--
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).
--
Remove the ns_ from if replying by e-mail (but keep posts in the
newsgroups if possible).
.
- Follow-Ups:
- References:
- Critical difference between behaviour of @@sqlstatus vs. MS-SQL @@FETCH_STATUS?!?
- From: Riko
- Re: Critical difference between behaviour of @@sqlstatus vs. MS-SQL @@FETCH_STATUS?!?
- From: David Kerber
- Re: Critical difference between behaviour of @@sqlstatus vs. MS-SQL @@FETCH_STATUS?!?
- From: Riko
- Possible Bug with TOP N clause in cursor definition. Re: Critical difference between behaviour of @@sqlstatus vs. MS-SQL @@FETCH_STATUS?!?
- From: Riko
- Critical difference between behaviour of @@sqlstatus vs. MS-SQL @@FETCH_STATUS?!?
- Prev by Date: Possible Bug with TOP N clause in cursor definition. Re: Critical difference between behaviour of @@sqlstatus vs. MS-SQL @@FETCH_STATUS?!?
- Next by Date: Re: Possible Bug with TOP N clause in cursor definition. Re: Critical difference between behaviour of @@sqlstatus vs. MS-SQL @@FETCH_STATUS?!?
- Previous by thread: Possible Bug with TOP N clause in cursor definition. Re: Critical difference between behaviour of @@sqlstatus vs. MS-SQL @@FETCH_STATUS?!?
- Next by thread: Re: Possible Bug with TOP N clause in cursor definition. Re: Critical difference between behaviour of @@sqlstatus vs. MS-SQL @@FETCH_STATUS?!?
- Index(es):
Relevant Pages
|