RE: Using Cursors
From: GreyAlien007 (GreyAlien007_at_discussions.microsoft.com)
Date: 01/24/05
- Next message: Rob Meade: "Changing a null to another value in select?"
- Previous message: Kathi Kellenberger: "RE: extended stored procedure question"
- In reply to: peterDavey: "Using Cursors"
- Next in thread: David Buchanan: "Re: Using Cursors"
- Messages sorted by: [ date ] [ thread ]
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
>
>
>
- Next message: Rob Meade: "Changing a null to another value in select?"
- Previous message: Kathi Kellenberger: "RE: extended stored procedure question"
- In reply to: peterDavey: "Using Cursors"
- Next in thread: David Buchanan: "Re: Using Cursors"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|