You are on page 1of 5

How to repair the collation

conflict in SQL Server



1 January 2013
Error description
All those who have been working with SQL Server 7, when they are passed
to the 2000 version have been dealing with the following error:

Can not resolve collation conflict for equal to operation

<< Can not resolve collation conflict between SQL_Latin1_General_CP1_CI_AS and
Latin1_General_CI_AS union operation >>

This mean that every comparisons between characters (char and varchar
fields) is subject to the rules imposed by the collation. Each field has its
own character collation.

Error description
This error incur when you try to compare two fields that have different
collation, and then SQL Server can not decide the outcome of the
comparison.

This happens especially when comparing data from different environments or
db born initially with version 7 of SQL Server.

Generally this error involve comparisons of fields with collate
SQL_Latin1_General_CP1_CI_AS (the default when you import a db from SQL
Server 7) and Latin1_General_CI_AS (default SQL Server 2000 collation). This
kind of error generally affect joins between fields of type text.
The solution
To avoid this error, you must do a cast (conversion) of one of the fields.
Suppose we have the tab1 with the field of c1 char (2) and collation
SQL_Latin1_General_CP1_CI_AS, and the table tab2 with the field c2 char (2 )
and Latin1_General_CI_AS collation, the following query:

select *
from tab1
join tab2 on tab1.c1 = tab2.c2
inevitably return an error, while
Select *
from tab1
join tab2 on CAST (tab1.c1 as char (2)) collate Latin1_General_CI_AS = tab2.c2
allows you to operate the join. It 'clear that any indexes on the field c1 in
the table tab1 go to hell but at least it solves the problem.
CREATE TABLE #TEMPCOMPETENZE
(
Tipo varchar(1000) ,
IdScheda varchar(1000) ,
Campo1 varchar(1000) ,
Campo2 varchar(1000) ,
Campo3 varchar(1000) ,
Campo4 varchar(1000) ,
Campo5 varchar(1000) ,
Campo6 varchar(1000) ,
Campo7 varchar(1000) ,
Campo8 varchar(1000) ,

Campo28 varchar(1030)
)
CREATE TABLE #TEMPCOMPETENZE
(
Tipo varchar(1000) COLLATE Latin1_General_CI_AS,
IdScheda varchar(1000) COLLATE Latin1_General_CI_AS,
Campo1 varchar(1000) COLLATE Latin1_General_CI_AS,
Campo2 varchar(1000) COLLATE Latin1_General_CI_AS,
Campo3 varchar(1000) COLLATE Latin1_General_CI_AS,
Campo4 varchar(1000) COLLATE Latin1_General_CI_AS,
Campo5 varchar(1000) COLLATE Latin1_General_CI_AS,
Campo6 varchar(1000) COLLATE Latin1_General_CI_AS,
Campo7 varchar(1000) COLLATE Latin1_General_CI_AS,
Campo8 varchar(1000) COLLATE Latin1_General_CI_AS,

Campo28 varchar(1030) COLLATE Latin1_General_CI_AS
)

You might also like