Code Snippets

Dynamicaly ADD Query in a Cursor in Stored Procedure



To know what a cursor is and how it can be used in a stored procedure,read my previous article

http://www.shefeekj.com/?p=230

Here is the code snippets to add query in a cursor dynamically

SET @sqlQuery = … (build the dinamic sql query)

SET @cursorQuery = ‘DECLARE myCursor CURSOR GLOBAL FAST_FORWARD FOR ‘ + @sqlQuery

EXEC @cursorQuery

OPEN myCursor

FETCH NEXT FROM myCursor INTO …

CLOSE myCursor

DEALLOCATE myCursor

Share

Thanks for reading my blog. If you like what I write, why not subscribe to my feed?

If you are busy, I can send the latest post to your email. Just subscribe to my email updates.

 

Enter your email address:

Delivered by FeedBurner

Discussion

No comments for “Dynamicaly ADD Query in a Cursor in Stored Procedure”

Post a comment