Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Join Expand / Collapse
Posted Monday, October 22, 2012 6:00 AM



Group: General Forum Members
Last Login: Today @ 4:17 AM
Points: 1,963, Visits: 2,407

I have two tables employee(employeeId,LocationID) and employeelocation(employeeId,Locationcode).
Both these tables exists in doff database. LocationCode in EmployeeLocation table has char values like XA,Ca etc and in employee table it has ID rather than Code. So how can I put join on these two columns of these two tables. this Location ID and LocationCode is stored in a table Location(LocationID, LocationCode)..

plzz give a solution

To get quick answer follow this link:
Post #1375360
Posted Monday, October 22, 2012 6:07 AM


Group: General Forum Members
Last Login: Friday, December 12, 2014 10:09 AM
Points: 2,876, Visits: 5,201
Plzz follow this:

"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1375363
Posted Monday, October 22, 2012 7:07 AM



Group: General Forum Members
Last Login: Today @ 3:26 AM
Points: 14,205, Visits: 28,536
You have to include the database name if the database resides on the same server:

FROM MyDatabase.MySchema.MyTable;

That will get it done. You can then join on the appropriate column.

"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server Query Performance Tuning
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1375406
Posted Monday, October 22, 2012 9:06 AM

SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 12:39 PM
Points: 4,049, Visits: 9,211
Using the information given you can do something like this

FROM OneDatabase.dbo.EmployeeLocation el
JOIN SomeDatabase.dbo.Location l ON el.locationcode = l.locationcode
JOIN AnotherDatabase.dbo.Employee e ON el.employeeID = e.employeeID
AND l.locationID = e.locationID

You need to change the names of the databases and include the fields that you need insteadof the asterisk.
I'm assuming that your databases are on the same server.

Luis C.
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1375486
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse