• What I have posted isn't Dynamic SQL... it's a hardcoded query like you might have in any stored procedure but it's necessarily stored in a string simply because that's what OPENQUERY requires. I know that OPENROWSET doesn't allow the use of variables and must be dynamic to make changes but I haven't actually tried using a variable with OPENQUERY so I don't know if "simple" query replacement would work here or not. Of course, "full" dynamic SQL like that used for making changes to an OPENROWSET would work but I absolutely understand the desire to avoid such a thing.

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