Results 1 to 5 of 5

Thread: Help

  1. #1
    Join Date
    Mar 2012
    Posts
    7

    Unanswered: Help

    Hello,
    i have one question.
    I have made query that pull some data from one database, but i need to pull exact the same data from another database.
    How can i do this? Is it possible?
    here is my query:
    SELECT GKTotal.Konto, KtPlan.Naziv, GKTotal.Mjesec, GKTotal.TroMjID, GKTotal.WDug, GKTotal.WPot
    FROM Igi2009.dbo.GKTotal GKTotal, Igi2009.dbo.KtPlan KtPlan
    WHERE GKTotal.Konto = KtPlan.Konto AND ((GKTotal.Mjesec=12) AND (GKTotal.TroMjID='103') AND (Len(GKTotal.konto)=6) AND (GKTotal.Konto Like '3%'))

    Only difference is that second database have name: igi2008
    Any ideas??
    Tnx
    Last edited by soky; 03-20-12 at 05:16.

  2. #2
    Join Date
    Aug 2004
    Location
    Dallas, Texas
    Posts
    831
    Quote Originally Posted by soky View Post
    Hello,
    i have one question.
    I have made query that pull some data from one database, but i need to pull exact the same data from another database.
    How can i do this? Is it possible?
    here is my query:
    SELECT GKTotal.Konto, KtPlan.Naziv, GKTotal.Mjesec, GKTotal.TroMjID, GKTotal.WDug, GKTotal.WPot
    FROM Igi2009.dbo.GKTotal GKTotal, Igi2009.dbo.KtPlan KtPlan
    WHERE GKTotal.Konto = KtPlan.Konto AND ((GKTotal.Mjesec=12) AND (GKTotal.TroMjID='103') AND (Len(GKTotal.konto)=6) AND (GKTotal.Konto Like '3%'))

    Only difference is that second database have name: igi2008
    Any ideas??
    Tnx
    Have you set up the second database as a linked server?

  3. #3
    Join Date
    Mar 2012
    Posts
    7
    I have not.
    So i need create linked server with second database (both databases are on the same SQL server) and then i can normally select from second database? I can just continue adding on previous query??

  4. #4
    Join Date
    Aug 2004
    Location
    Dallas, Texas
    Posts
    831
    Quote Originally Posted by soky View Post
    I have not.
    So i need create linked server with second database (both databases are on the same SQL server) and then i can normally select from second database? I can just continue adding on previous query??
    Well if they are on the same server then it's not necessary to create a linked server.

    select t1.col1,t2.col2
    from server.database1.dbo.table1 t1
    inner join server.database2.dbo.table2 t2 on t1.col1 = t2.col2

    This is a very simplistic representation.

  5. #5
    Join Date
    Mar 2012
    Posts
    7
    OK, tnx a lot!!!! You'r the man!!! :-)
    I thought in this way so linked server have no sens to me, but tnx a lot!!!
    Now i need to make pivot table, example

    Konto|MT|Price 2008|Price2009|
    3221 |3 |15.214,00 |20.000.00
    3441 |3 |10.014,00 |25.931.00
    3351 |3 |13.694,00 |19.111.00
    3361 |3 |19.521,00 |13.000.00

    Price 2008 is from one database, and 2009 from another, but query put data bellow not on right side,next to price 2008, so i think pivot table is solution??
    I hope this is not hard to make.
    And sorry, my english is very very bad, i know :-D

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •