Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collation Problem - SQL Server 2005

I would like to understand this error I'm getting on a SQL Server 2005 instance. Error below:

Cannot resolve the collation conflict between "Latin1_General_CI_AI" and "SQL_Latin1_General_CP1_CI_AI" in the equal to operation.

Both databases included in a simple query have Latin1 General CI AI, but had SQL Latin1 General CP1 CI AI before. I changed the collation trying to match them but still get the aforementioned error every time I try to join a temp table with a table from a user database. I have no issues creating temp tables.

like image 859
Joel Avatar asked Dec 18 '22 07:12

Joel


2 Answers

When you join you can use COLLATE to change the collation on the fly to make them the same:

select c.name, o.orderid from customer as c
inner join order as o on c.custid = o.custid COLLATE SQL_Latin1_General_CP1_CI_AI

Assuming that cust is SQL_Latin1_General_CP1_CI_AI and order is some other collation, the above query will fix the problem.

like image 93
monibius Avatar answered Dec 22 '22 00:12

monibius


Look in the table design that both fields you do the join have the same collation settings.

ALTER TABLE <table>
ALTER COLUMN <column> VARCHAR(200) COLLATE Latin1_General_CI_AI
GO
like image 43
David Aleu Avatar answered Dec 21 '22 23:12

David Aleu