• Steve Smith-163358 (10/3/2013)


    Thank you all very much for your replies, and thank you Jeff for the excellent article that Alan linked to earlier.

    I had often read about the merits of set based v's cursors before, but never really grasped the concepts.

    More to the point, I didn't realise that half of the code I wrote was set based and half wasn't 🙂

    Alan, thank you for the code sample.

    I've tried using it, but unfortunately I start hitting limits with the size of the data type.

    In my test example that I'm using, I have 10,000 tables that I want to delete.

    It appears, that due to the number of tables, I can't populate them all into the parameter, even using varchar(max)

    With this many tables, I may be stuck with cursors or similar procedures

    I don't believe that you're hitting the limits of the datatype (VARCHAR(MAX)). What you are hitting the limit of is how to display the code... normally 8K bytes (or less depending on your column width settings) even if the variable contains much more.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)