简体   繁体   中英

SQL Server : error joining two tables from two different databases

I am using SSMS, I am trying to join two tables from two different databases, both in the same server.

The two tables have a common id column.

My query is:

select * 
from db1.dbo.EPH e 
join db2.dbo.SALARIE s on e.id = s.id

I'm getting this error:

Unable to resolve collation conflict between "Latin1_General_CI_AI" and "French_CI_AS" in operation equal to.

Your two databases don't have the same collation. You need to specify the "COLLATE DATABASE_DEFAULT" clause in your join.

select * from db1.dbo.EPH e join db2.dbo.SALARIE s on e.id COLLATE DATABASE_DEFAULT=s.id COLLATE DATABASE_DEFAULT

It should do the trick.

In Microsoft SQL Server, the collation can be set at the column level. When you compare (or concatenate) two columns having different collation in a query.

Example:

SELECT * FROM db1.dbo.EPH e
JOIN db2.dbo.SALARIE s
ON e.id COLLATE DATABASE_DEFAULT = s.id

Try to use COLLATE Latin1_General_CI_AS

select * 
from db1.dbo.EPH e 
join db2.dbo.SALARIE s on
e.id COLLATE Latin1_General_CI_AS = s.id
COLLATE Latin1_General_CI_AS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM