connect to a different database

  • Hi guys

    I have a table sitting in a database where I dont have permissions to create or save a table.Its our main database. I can just run queries on it.

    Now I need to save the results of the below mentioned query into my personal database called "data".

    This main database name is "MainDb" and the table which I am using from this database is called

    DF_claim.

    Now how do I modify this query so that it saves the results in my database or how do I run a query in my database which is pointing to the main database??

    select Year(a.application_date) as app_year,

    month(a.application_date) as app_month_num,

    datename(mm,a.application_date) as app_month,

    from DF_CLAIM as a

    and a.application_date between '1 jul 2008' and '30 sep 2008'

    Thanks guys

    Cheers

  • You can reference the main database by name in your from clause.

    FROM MainDb.dbo.DF_Claim

    You can do that from your own database. If you want to insert the results into a table, your query would look like:

    SELECT ...

    INTO MyNewTable

    FROM MainDb.dbo.DF_Claim

    WHERE ...

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • Thanks for that

    Cheers

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

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