Passing a Dynamic Query to a cursor

  • Hi,

     

    I am wondering if there is any way where a string variable can be passed to a cursor instead of a select statement like

     

    DECLARE @sql_str VARCHAR(255)

    SET @sql_str='SELECT * FROM EMP'

    DECLARE myEmp CURSOR FOR  @sql_str

     

    Is there any way where in I can accomplish the above requirement of passing a dynamic sql to a cursor.

     

    Any help would be highly appreciated.

     

    Thanks

    -Prasad

     

     

     

     

     

    Prasad Bhogadi
    www.inforaise.com

  • Put the whole statement into your string and execute it dynamically as explained here http://www.sommarskog.se/dynamic_sql.html#cursor

     

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply