• D.Post (11/21/2012)


    Is this correct or is there another way to do this?

    Something to do with SQL Injection? (No fear of)

    No. No way to stipulate the database name in a variable without using dynamic SQL of some sort.

    So far as SQL injection goes, your code is wide open for it the way @DBName is currently used. The best way around it is to check that the content of @DBName actually exists in sys.databases or throw a fatal error.

    Items 2 and 4 may run but they don't actually work the way you would expect. Since you double single-quoted the @ck variable names, the variable names become quoted literals rather than variables.

    --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)