“Deferred prepare could not be completed” error when using local database as linked server

前端 未结 5 570
旧巷少年郎
旧巷少年郎 2021-01-17 07:49

I created a Linked Server from my local Sql Server, as given in

http://sqlserverplanet.com/dba/local-linked-server

However when I try to execute a stored pro

5条回答
  •  无人及你
    2021-01-17 08:22

    I had the same error trying to query through a linked server. However, I was querying a view on the target server, not a stored procedure.

    The target server's view was created like this:

    CREATE VIEW vABC AS
        SELECT ... FROM Table1
        UNION ALL
        SELECT ... FROM Table2
    

    To fix the problem, I did an alter view, and wrapped the two UNION statements in a subquery, like this:

    CREATE VIEW vABC AS
        SELECT * FROM (
            SELECT ... FROM Table1
            UNION ALL
            SELECT ... FROM Table2
        ) T
    

    Must be some metadata issue with the original view.

    Hope this helps you!

提交回复
热议问题