Cursor with exec instead of select

  • Hi,

    Is it possible to declare a dynamic sql instead of static with a cursor as follows :

     declare CheckColumn cursor for

       exec('select distinct ' +  @ColName + ' from ' + @TableName)

    Or

     declare CheckColumn cursor for

       exec("select distinct " +  @ColName + " from " + @TableName)

     

    Thansk in advance

  • Hi,

    I am about 99.9% certain it isn't possible.

    Could you give us an idea of the problem you are trying to solve here.

    You need to do a lot of research on Dynamic sql before deciding to go down that road - it isn't the easy fix people think it is and has a whole new world of downsides to the un-initiated.

    And while you are looking into that, search for cursorless loops.

    Have fun

    Steve

    We need men who can dream of things that never were.

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

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