Get Result from two diffrent databse

Hello Expert, i am trying to writ an sql statment that retrieve a data from two defrrent databse depend on a condition, will actully can i do this in sql??
i have a table that contain a user id i want to get the full name either from db1.table1 or db2.table1 my sql statement is

SELECT     dbo.tblCallDetail.UserId, dbo.tblMinisUser.FullName, pr1.dbo.GetUserDetailsE.EngName
FROM        
dbo.tblCallDetail INNER JOIN  
dbo.tblMinisUser ON dbo.tblCallDetail.UserId = dbo.tblMinisUser.UserId
AND
dbo.tblCallDetail.UserId = dbo.tblMinisUser.UserId INNER JOIN
pr1.dbo.GetUserDetailsE ON dbo.tblCallDetail.UserId = pr1.dbo.GetUserDetailsE.PERUserName AND
dbo.tblCallDetail.UserId = pr1.dbo.GetUserDetailsE.PERUserName

but its wrong sql how can i correct the sql?
LVL 1
AZZA-KHAMEESAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
let*s try this:
SELECT  cd.UserId, mu.FullName, gud.EngName
FROM dbo.tblCallDetail cd
LEFT JOIN  dbo.tblMinisUser mu 
  ON cd.UserId = mu.UserId 
LEFT JOIN pr1.dbo.GetUserDetailsE gud
  ON cd.UserId = gud.PERUserName 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AZZA-KHAMEESAuthor Commented:
its working but can i show the fields mu.FullName, gud.EngName in one field called FullUserName ??
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
no problem:
SELECT  cd.UserId, COALESCE( gud.EngName, mu.FullName ) FullUserName 
FROM dbo.tblCallDetail cd
LEFT JOIN  dbo.tblMinisUser mu 
  ON cd.UserId = mu.UserId 
LEFT JOIN pr1.dbo.GetUserDetailsE gud
  ON cd.UserId = gud.PERUserName 

Open in new window

0
AZZA-KHAMEESAuthor Commented:
Thank you :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.