0

I have 2 databases on the same server. One called Clients and one called Company. For both database, it contains information like, company name, address and telephone number. In the Company database, it is possible that the Client database may contain the same information in the Company database. I want to get all the Data from the Company database which have the same telephone number of any data in the Client database. How would I go about doing this??

Thanks

2
  • 2
    You need to give us the table structure of both databases, and explicitely state how the telephone numbers are stored and what you really mean by "all the data". Commented Jul 6, 2015 at 15:10
  • 2
    If the account has access to both databases, and your table keys match, you can join across databases by specifying the fully qualified name ([Database].[Schema].[Table]) Commented Jul 6, 2015 at 15:11

2 Answers 2

2
SELECT co.Name, co.Address, co.Phone, cl.Name, cl.Address, cl.Phone 
FROM Company.dbo.Table co
JOIN Client.dbo.Table cl on cl.Phone = co.Phone

Give this a try.

You may have to also make sure they have the same collation. The query may not work if the collation of the databases is different.

Sign up to request clarification or add additional context in comments.

Comments

1

Is there only one table that matches in both databases that you are needing to look through?

Select comp.*
From Company.dbo.TableName comp
Join Clients.dbo.TableName cl on comp.PhoneNbr = cl.PhoneNbr

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.