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
Author
Message
Posted Monday, October 22, 2012 6:00 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, July 25, 2014 12:34 AM
Points: 1,888, Visits: 2,326
Hi,

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:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1375360
Posted Monday, October 22, 2012 6:07 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, August 26, 2014 7:27 AM
Points: 2,836, Visits: 5,067
Plzz follow this: http://www.sqlservercentral.com/articles/Best+Practices/61537/


_____________________________________________
"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


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 10:09 AM
Points: 15,661, Visits: 28,050
You have to include the database name if the database resides on the same server:

SELECT *
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 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

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


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Yesterday @ 10:52 PM
Points: 3,541, Visits: 7,637
Using the information given you can do something like this

SELECT *
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