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

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