Linked server queries

  • Hi there,

    I'm running a query, which accesses a database on another server.

    Executing normal selects is not a problem, but as soon as I run a correlated select, the following error appears...

    "Statement(s) could not be prepared"

    According to Microsoft we have to wait for the next service pack.. Does anyone have another idea??

    Thanks!!

     

     

  • You could pop the data from your correlated (sub) query into a temp table on the local server and use that in your transaction instead. Keep in mind performance issues and the size of your tempdb

    Max

  • I have encountered this before and got around it by rewriting the query 'the other way round'. Instead of the main query being on the local server and the sub-query on the remote, make the main query on the remote (still running on the local and using 4-part notation) or vice versa (I forget the actual example). eg, instead of :

    SELECT a.* FROM dbo.TableA a

    JOIN RemoteServer.DatabaseB.dbo.TableB b

    ON b.KeyField = a.KeyField

    try :

    SELECT a.* FROM RemoteServer.DatabaseB.dbo.TableB b

    JOIN dbo.TableA a

    ON a.KeyField = b.KeyField

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply