• I recommend the following steps to change it into a remote query:

    1) change the main query completely into a dynamic query so it will run when using EXECUTE(@sql) where @sql is the string holding the main query. This will require to replace all single quotation marks with two single quotation marks and to add a quotation mark at the beginnig and at the end.

    2) Verify, the query returns the same data as previously.

    3) Remove each and every occurence of ENIQSQLSERVER. (including the dot, this will change the table reference to a three-part-named reference).

    4) Execute the query remote using EXECUTE(@sql) AT ENIQSQLSERVER

    5) see what happens 😉



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]