Re: How to define cursor on temp table?
From: Aaron [SQL Server MVP] (ten.xoc_at_dnartreb.noraa)
Date: 08/24/04
- Next message: Aaron [SQL Server MVP]: "Re: Parallelism in SQL queries"
- Previous message: Russ Ferrill: "Re: Passing a table or cursor into a stored procedure"
- In reply to: Snake: "How to define cursor on temp table?"
- Next in thread: Partha Mandayam: "Re: How to define cursor on temp table?"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 24 Aug 2004 11:40:50 -0400
Maybe you need to show your code, because this works fine for me:
CREATE PROCEDURE dbo.blat
AS
BEGIN
SET NOCOUNT ON
SELECT a=1,b=2 INTO #tmp
DECLARE @a TINYINT, @b TINYINT
DECLARE foo CURSOR FOR
SELECT a,b FROM #tmp
OPEN foo
FETCH NEXT FROM foo INTO @a, @b
WHILE (@@FETCH_STATUS=0)
BEGIN
PRINT @a
PRINT @b
FETCH NEXT FROM foo INTO @a, @b
END
CLOSE foo
DEALLOCATE foo
DROP TABLE #tmp
END
GO
EXEC dbo.blat
GO
DROP PROC dbo.blat
GO
-- http://www.aspfaq.com/ (Reverse address to reply.) "Snake" <Snake@discussions.microsoft.com> wrote in message news:80B78D02-6257-4B37-82ED-DC456E592826@microsoft.com... > I have a procedure that defines a cursor on a temp table (#temp1) but at > run-time the following message is displayed " Invalid object name #temp1 " on > the Declare statement for the cursor. This implies that one can not open a > cursor on a local temp table created in the same procedure. > > So now I need an alternate method of simulating a cursor in my While-loop in > my stored proc. Any suggestions? > > Thanks, > Michael
- Next message: Aaron [SQL Server MVP]: "Re: Parallelism in SQL queries"
- Previous message: Russ Ferrill: "Re: Passing a table or cursor into a stored procedure"
- In reply to: Snake: "How to define cursor on temp table?"
- Next in thread: Partha Mandayam: "Re: How to define cursor on temp table?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|