Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8712871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:12:05+00:00 2026-06-13T05:12:05+00:00

Hello and thank you very much for your time. I am using SQL Server

  • 0

Hello and thank you very much for your time. I am using SQL Server 2008. My challenge is as follows:

I have 3 databases Q_DB, CAN_DB, USA_DB. CAN_DB and USA_DB have the same tables but represent two different countries

The Q_DB has tables of queues. One table is called ACCOUNTS and the columns of interest are ACCOUNTID and SERVER

I want to query the information on the other two databases from the fields of ACCOUNTS. An example is:

Q_DB.dbo.ACCOUNTS

  • ID123 CAN_DB
  • ID456 USA_DB
  • ID789 CAN_DB

I know I can do it this way, but it I was wondering if there is any other approach to obtain the result.

SELECT ACTNAME, AMTDUE, SHIPCOUNTY  
FROM CAN_DB.dbo.Accts 
WHERE ACCTID IN(SELECT ACCOUNTID FROM Q_DB.dbo.ACCOUNTS WHERE SERVER IN('CAN_DB')
UNION ALL
SELECT ACTNAME, AMTDUE, SHIPCOUNTRY 
FROM USA_DB.dbo.Accts
WHERE ACCTID IN(SELECT ACCOUNTID FROM Q_DB.dbo.ACCOUNTS WHERE SERVER IN('USA_DB')

Any help or opinions or suggestions would be greatly appreciated . Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:12:06+00:00Added an answer on June 13, 2026 at 5:12 am

    I don’t see why you are using IN with a single value (CAN_DB).

    Also, you should precognize EXISTS instead of IN.

    SELECT ACTNAME, AMTDUE, SHIPCOUNTRY  
    FROM CAN_DB.dbo.Accts a1
    WHERE EXISTS (SELECT * FROM Q_DB.dbo.ACCOUNTS WHERE ACCTID = a1.ACCTID AND SERVER = 'CAN_DB')
    UNION ALL
    SELECT ACTNAME, AMTDUE, SHIPCOUNTRY 
    FROM USA_DB.dbo.Accts a2
    WHERE EXISTS (SELECT * FROM Q_DB.dbo.ACCOUNTS WHERE ACCTID = a2.ACCTID AND SERVER = 'USA_DB')
    

    Note: Using UNION ALL will return duplicates (if there are some). To have the query select unique rows, use the keyword UNION instead.

    EDIT: If you want to sum the AMTDUE from both servers according to same ACTNAME and SHIPCOUNTRY :

    SELECT  COALESCE(can.ACTNAME,usa.ACTNAME) as ACTNAME,
            COALESCE(can.AMTDUE,0)+COALESCE(usa.AMTDUE,0) as AMTDUE,
            COALESCE(can.SHIPCOUNTRY,usa.SHIPCOUNTRY) as SHIPCOUNTRY  
    FROM    CAN_DB.dbo.Accts can
    FULL OUTER JOIN USA_DB.dbo.Accts usa
    ON      can.ACTNAME = usa.ACTNAME AND 
            can.SHIPCOUNTRY = usa.SHIPCOUNTRY
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello everyone and thank you very much for your time. Basically what I am
Hello and thank you in advance, I am very much a Django/Python noobie. I
Hello i have a very simple question, I have initialized some variables and started
Hello: I am teaching myself Linq to Sql in C#. Because I am using
Hello, I have the following sql table + data: CREATE TABLE IF NOT EXISTS
Suppose file1 looks like this: bye bye hello thank you And file2 looks like
Hello friends I have tried many times but I am not successful than please
Hello guys. I think it isn't possible just using PHP, but just to be
hello, how can i set cookies like 'last_visit' if the user have more than
I have this kinda template text : Hello {#Name#}, Thanks for coming blah on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.