Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parameters to Cursor !

Status
Not open for further replies.

fixthebug2003

Programmer
Oct 20, 2003
294
US
Hi
Is it possible to pass a Parameter to a Cursor and then open it dynamically. Can someone point to the right resource for this?

Thanks
Fixthebug2003
 
Unless I am much mistaken, parameters (or local variables) that are declared outside the CURSOR are still valid inside the cursor.

So:

DECLARE @MyParam1 varchar(10), @MyParam2 varchar(10)

DECLARE MyCursor CURSOR FOR
SELECT Column1, Column2
FROM MyTable

OPEN MyCursor

FETCH NEXT FROM MyCursor INTO @MyParam1, @MyParam2

WHILE @@FETCH_STATUS <> -1
BEGIN

IF @@FETCH_STATUS <> -2
BEGIN
' You can do whatever you want with @MyParam1, @MyParam2
...Code
END

FETCH NEXT FROM MyCursor INTO @MyParam1, @MyParam2
END

CLOSE MyCursor
DEALLOCATE MyCursor

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top