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