How to do a distributed query?

  • Hi everybody, i need to do a query including a Table of a different server of which i am connected

    is it possible to do that using T sql ?

    i need to do a select of a table A of the server which i am connected including  a Table of an outer server

    sorry my bad english...

     

  • There are many ways to achieve this.

    Perhaps it's better for you to look up 'distributed queries' in Books On Line to see what is available.

    /Kenneth

  • if you have a linked server setup then

    SELECT *

    FROM OPENQUERY(servername,'SELECT * FROM [TableB]')

    otherwise

    SELECT *

    FROM OPENROWSET('MSDASQL','servername';'loginname';'password','SELECT * FROM [TableB]')

    you can also join local and remote tables like this

    SELECT *

    FROM [TableA] a

    INNER JOIN OPENQUERY(servername,'SELECT * FROM [TableB]') b

    ON b.key = a.key

    or

    SELECT *

    FROM [TableA] a

    INNER JOIN OPENROWSET('MSDASQL','servername';'loginname';'password','SELECT * FROM [TableB]') b

    ON b.key = a.key

    Far away is close at hand in the images of elsewhere.
    Anon.

  • mmmm i have the next error

     

    Server: Msg 7399, Level 16, State 1, Line 1

    OLE DB provider 'MSDASQL' reported an error. 

    [OLE/DB provider returned message: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified]

    I could solved Thanks my friend, changed  my provider

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

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