在同一 SQL.Server 上跨 2 个数据库加入时的 COLLATE 问题

COLLATE issue on joining across 2 database on same SQL.Server

我不断收到此错误:

Cannot resolve the collation conflict between "Latin1_General_BIN" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.

我不知道如何解决它。

我通过连接两个数据库中具有不同名称的列来连接同一台服务器上的两个不同数据库。

SELECT t1.ColumnNameDB1, t2.ColumnNameDB2
FROM DB1.schema.TableName AS t1
INNER JOIN DB2.schema.TableName as t2
ON t1.ColumnNameDB1 =  t2.ColumnNameDB2

我正在绞尽脑汁想弄清楚我做错了什么。

您可以尝试在连接级别明确指定排序规则。

SELECT t1.ColumnNameDB1, t2.ColumnNameDB2
FROM DB1.schema.TableName AS t1
INNER JOIN DB2.schema.TableName as t2
ON t1.ColumnNameDB1 =  LTRIM(RTRIM(t2.ColumnNameDB2)) COLLATE SQL_Latin1_General_CP1_CI_AS 

使用这个:

SELECT t1.ColumnNameDB1,
 t2.ColumnNameDB2 FROM
 DB1.schema.TableName AS t1 INNER JOIN
 DB2.schema.TableName as t2 ON
 t1.ColumnNameDB1 Collate database_default =
 t2.ColumnNameDB2 collate database_default