Re: number of rows in cursor
From: oj (nospam_ojngo_at_home.com)
Date: 03/26/04
- Next message: Karl Gram: "Re: Use variables with CREATE and DROP"
- Previous message: Roji. P. Thomas: "Re: How to: If a row doesn't exist return a null as that field in a select statement"
- In reply to: Min J.Deng: "Re: number of rows in cursor"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 26 Mar 2004 10:30:06 -0800
Here are some examples:
DECLARE authors_cursor insensitive CURSOR FOR(
SELECT au_lname
FROM pubs..authors
WHERE state like 'CA')
declare @l sysname
OPEN authors_cursor
FETCH NEXT FROM authors_cursor into @l
WHILE (@@FETCH_STATUS = 0)
BEGIN
--print @au_lname
FETCH NEXT FROM authors_cursor into @l
END
SELECT @@CURSOR_ROWS as [@@cursor_rows]
CLOSE authors_cursor
DEALLOCATE authors_cursor
go
DECLARE authors_cursor CURSOR keyset FOR(
SELECT au_lname
FROM pubs..authors
WHERE state like 'CA')
declare @l sysname
OPEN authors_cursor
FETCH NEXT FROM authors_cursor into @l
WHILE (@@FETCH_STATUS = 0)
BEGIN
--print @au_lname
FETCH NEXT FROM authors_cursor into @l
END
SELECT @@CURSOR_ROWS as [@@cursor_rows]
CLOSE authors_cursor
DEALLOCATE authors_cursor
go
DECLARE authors_cursor CURSOR static FOR(
SELECT au_lname
FROM pubs..authors
WHERE state like 'CA')
declare @l sysname
OPEN authors_cursor
FETCH NEXT FROM authors_cursor into @l
WHILE (@@FETCH_STATUS = 0)
BEGIN
--print @au_lname
FETCH NEXT FROM authors_cursor into @l
END
SELECT @@CURSOR_ROWS as [@@cursor_rows]
CLOSE authors_cursor
DEALLOCATE authors_cursor
go
-- -oj http://www.rac4sql.net "Min J.Deng" <jmdcorp@hotpop.com> wrote in message news:u9mFHZuEEHA.3980@TK2MSFTNGP09.phx.gbl... > Thank you for replying and giving me some good idea. > > But I still have some problems. > - @@CURSOR_ROW: is return -1. And in my understanding, that result because > it is a dynamic cursor which is changing. That is not what I expected. > So, what can I do to solve the problem? > > ----------- > -- This is example is : > DECLARE authors_cursor CURSOR FOR( > SELECT au_lname > FROM authors > WHERE state like 'CA') > > OPEN authors_cursor > > FETCH NEXT FROM authors_cursor > > WHILE (@@FETCH_STATUS = 0) > BEGIN > --print @au_lname > FETCH NEXT FROM authors_cursor > END > > SELECT @@CURSOR_ROWS > > CLOSE authors_cursor > DEALLOCATE authors_cursor > > --------- > > PS: can you give me an example? and more explaination. I think I should > learing more from you > > > > "Brian Moran" <brian@solidqualitylearning.com> wrote in message > news:u6m03ogEEHA.3676@TK2MSFTNGP09.phx.gbl... > > and I'd REALLY agree with David. > > > > The correct answer to any problem rarely includes a cursor. And I hope > this > > doesn't come off sounding the wrong way, but... I suspect that you're a > > beginner since you weren't able to find @@CURSOR_ROWS in Books Online. > > > > IMHO... beginners should NEVER use cursors in production systems becuase > > it's my experience that beginners typically don't have the experience to > > recognize when a cursor is a reasonable solution (sometimes they are) vs. > > when it's a horribly, horriby ineffecient thing to do (which is most of > the > > time....) > > > > > > > > -- > > > > Brian Moran > > Principal Mentor > > Solid Quality Learning > > SQL Server MVP > > http://www.solidqualitylearning.com > > > > > > "Min J.Deng" <jmdcorp@hotpop.com> wrote in message > > news:uWL9gJYEEHA.3392@TK2MSFTNGP11.phx.gbl... > > > let me ask a question: > > > -- how can we get number of rows that a cursor can fetch? > > > > > > > > > > > > > > >
- Next message: Karl Gram: "Re: Use variables with CREATE and DROP"
- Previous message: Roji. P. Thomas: "Re: How to: If a row doesn't exist return a null as that field in a select statement"
- In reply to: Min J.Deng: "Re: number of rows in cursor"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|