• For the most part, if you have defined a linked server, there is usually no need at all for OPENQUERY or anything like it. Just use a 4 part naming convention when referring to the tables in the linked server.

    The other thing is that you used the word "loop" a lot... generally speaking that's a form of death by SQL and should be avoided.

    Without seeing the code, there's not much else I can offer.... but if you've made a query so big that SQL Server hit the character limit on it, then you've made a query with hundreds of thousand of characters... don't post it here, please. I suspect it's something else wrong, though.

    Last, but not least, it would be handy if you posted the actual error messages. We're just guessing here.

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