RE: Using Cursors

From: GreyAlien007 (GreyAlien007_at_discussions.microsoft.com)
Date: 01/24/05


Date: Mon, 24 Jan 2005 10:57:05 -0800

Everything the others said about cursors is true. Do not use them if at all
possible.

Anyway, enough of that...so do you mean that you don't want to see

(x Rows affected) over and over again in the output pane? If so you can put

"set nocount on" at the top of the query.

"peterDavey" wrote:

> G'day,
> I'm moving from Oracle top SQL Server and starting recode my Oracle stored
> procedures into T-SQL. I have a procedure in Oracle that opens a cursor,
> loops through each record and does an update or insert where appropriate.
>
> I've just created my first cursor in T-SQL. It runs OK in Query Analyser
> but the problem is that it in the output pane it displays a separate query
> output for each record returned by the cursor. I don't want to it to output
> anything other than some summary stats afte it's completed. The code is
> below: I've excluded the SELECT statement because it's BIG.
>
> DECLARE curEpisode SCROLL CURSOR FOR
> SELECT
> some stuff ...
>
> OPEN curEpisode
>
> -- Perform the first fetch.
> FETCH NEXT FROM curEpisode
>
> -- Check @@FETCH_STATUS to see if there are any more rows to fetch.
> WHILE (@@FETCH_STATUS <> -1)
> BEGIN
> -- This is executed as long as the previous fetch succeeds.
> FETCH NEXT FROM curEpisode
> --... do stuff ....
> SET @counter = @counter + 1
> END
>
> CLOSE curEpisode
> DEALLOCATE curEpisode
> SELECT @counter
> GO
>
> Thanks in advance for any help.
>
> cheers
> peterDavey
> Austin Health
> Melbourne
>
>
>



Relevant Pages

  • Using Cursors
    ... I'm moving from Oracle top SQL Server and starting recode my Oracle stored ... I've just created my first cursor in T-SQL. ... DECLARE curEpisode SCROLL CURSOR FOR ... -- Perform the first fetch. ...
    (microsoft.public.sqlserver.programming)
  • Re: Using Cursors
    ... it seems I've stirred up a hornet's nest with my cursor question. ... finding the discussion valuable in my circumstances (moving from Oracle to ... SQL Server). ... > DECLARE curEpisode SCROLL CURSOR FOR ...
    (microsoft.public.sqlserver.programming)
  • Re: Using Cursors
    ... There's no doubt that in Oracle cursors are invaluable. ... the data with separate SQL statments to acheive what I want. ... convert that I'm sure I couldn't do without a cursor. ... > DECLARE curEpisode SCROLL CURSOR FOR ...
    (microsoft.public.sqlserver.programming)
  • Re: Using Cursors
    ... Somewhere inside your while loop body, ... statement or a call to a stored proc that contains a SELECT statement. ... I have a procedure in Oracle that opens a cursor, ... > DECLARE curEpisode SCROLL CURSOR FOR ...
    (microsoft.public.sqlserver.programming)
  • Re: ORATCL help needed!
    ... set cursor ... Wow, An Oratcl 3.3. ... It is coded with the the OCI layer released with Oracle ... Oracle instant client is available for many many platforms, ...
    (comp.lang.tcl)