Using Cursors
From: peterDavey (peter.davey_at_austin.org.au)
Date: 01/24/05
- Next message: David Portas: "Re: Using Cursors"
- Previous message: David Portas: "Re: Calculated field is calculated wrong"
- Next in thread: David Portas: "Re: Using Cursors"
- Reply: David Portas: "Re: Using Cursors"
- Reply: GreyAlien007: "RE: Using Cursors"
- Reply: David Buchanan: "Re: Using Cursors"
- Reply: peterDavey: "Re: Using Cursors"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 24 Jan 2005 21:58:37 +1100
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: David Portas: "Re: Using Cursors"
- Previous message: David Portas: "Re: Calculated field is calculated wrong"
- Next in thread: David Portas: "Re: Using Cursors"
- Reply: David Portas: "Re: Using Cursors"
- Reply: GreyAlien007: "RE: Using Cursors"
- Reply: David Buchanan: "Re: Using Cursors"
- Reply: peterDavey: "Re: Using Cursors"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|