October 22, 2012 at 6:00 am
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/
October 22, 2012 at 6:07 am
Plzz follow this: http://www.sqlservercentral.com/articles/Best+Practices/61537/
😉
October 22, 2012 at 7:07 am
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
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 22, 2012 at 9:06 am
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.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply