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


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: 2 days ago @ 11:16 PM
Points: 1,061, Visits: 1,151
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
Post #1375360
Posted Monday, October 22, 2012 6:07 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 12:08 PM
Points: 2,532, Visits: 4,339
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


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 3:57 PM
Points: 13,371, Visits: 25,152
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


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Yesterday @ 7:51 PM
Points: 958, Visits: 1,919
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.
Please don't trust me, test the solutions I give you before using them.
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