Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Joining Tables in seperate databases

Joining Tables in seperate databases

Scheduled Pinned Locked Moved Visual Basic
questiondatabase
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Just Greeky Creek
    wrote on last edited by
    #1

    Sorry for writing this Question to this part, but i write it in SQL part, i got no answer I have a table named "DebitsAndCredits" which has fallowing columns AccountNumber char(12) DebitCredit bit Amount money I have the same table in two databases which are MB0001 and MB0002 I would like to join them in a one result set.I write SELECT DISTINCT (AccountNumber ) , (SELECT SUM(Amount ) FROM DebitsAndCredits m WHERE m.DebitCredit =0 AND m.AccountNumber =f.AccountNumber ) as Credit,, (SELECT SUM(Amount ) FROM DebitsAndCredits m WHERE m.DebitCredit =1 AND m.AccountNumber =f.AccountNumber ) as Debit FROM DebitsAndCredits Order BY AccountNumber UNION SELECT DISTINCT (AccountNumber ) , (SELECT SUM(Amount ) FROM DebitsAndCredits m WHERE m.DebitCredit =0 AND m.AccountNumber =f.AccountNumber ) as Credit, (SELECT SUM(Amount ) FROM DebitsAndCredits m WHERE m.DebitCredit =1 AND m.AccountNumber =f.AccountNumber ) as Debit FROM DebitsAndCredits Order BY AccountNumber i dont know why it is not working in my way. I expect a table has three columns (AccountNumber,Credit,Debit ) as a result. What is Wrong?What do u offer for me?

    T 1 Reply Last reply
    0
    • J Just Greeky Creek

      Sorry for writing this Question to this part, but i write it in SQL part, i got no answer I have a table named "DebitsAndCredits" which has fallowing columns AccountNumber char(12) DebitCredit bit Amount money I have the same table in two databases which are MB0001 and MB0002 I would like to join them in a one result set.I write SELECT DISTINCT (AccountNumber ) , (SELECT SUM(Amount ) FROM DebitsAndCredits m WHERE m.DebitCredit =0 AND m.AccountNumber =f.AccountNumber ) as Credit,, (SELECT SUM(Amount ) FROM DebitsAndCredits m WHERE m.DebitCredit =1 AND m.AccountNumber =f.AccountNumber ) as Debit FROM DebitsAndCredits Order BY AccountNumber UNION SELECT DISTINCT (AccountNumber ) , (SELECT SUM(Amount ) FROM DebitsAndCredits m WHERE m.DebitCredit =0 AND m.AccountNumber =f.AccountNumber ) as Credit, (SELECT SUM(Amount ) FROM DebitsAndCredits m WHERE m.DebitCredit =1 AND m.AccountNumber =f.AccountNumber ) as Debit FROM DebitsAndCredits Order BY AccountNumber i dont know why it is not working in my way. I expect a table has three columns (AccountNumber,Credit,Debit ) as a result. What is Wrong?What do u offer for me?

      T Offline
      T Offline
      The Man from U N C L E
      wrote on last edited by
      #2

      you must specify the database names in the query eg. Select ..... from MB0001..DebitsAndCredits m1 ...... Union Select ..... from MB0002..DebitsAndCredits m2 ...... If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850)

      J 1 Reply Last reply
      0
      • T The Man from U N C L E

        you must specify the database names in the query eg. Select ..... from MB0001..DebitsAndCredits m1 ...... Union Select ..... from MB0002..DebitsAndCredits m2 ...... If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850)

        J Offline
        J Offline
        Just Greeky Creek
        wrote on last edited by
        #3

        I have already done that. But i realized i forgot writing that when i asked

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups