Select table from another Database

  • Hi

    All

    I have Two database named test1 and test2

    in each database one table named table1 and table2 respectively

    I am currently in database test1 and I want the query to select records from table2 of test2 database

    So my query may be

    Select * from test2.table2 and it gives me error

    So what be the quey.

    Pl help me

  • Select * from test2..table2

    two dots.

    Joe

     

  • And if these databases happen to be on separate instances, then look up BOL for "linked servers".

  • And, you might want to consider using the user name in the 3 part naming convention as part of best practices...

    --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)
    Intro to Tally Tables and Functions

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

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