SQL 2005 collation conflict for replace operation

Here is a test case that reproduces the problem:

select REPLACE(child.type + child.name, ' ', '_' )
from sys.sql_dependencies
inner join sys.objects child
on child.object_id = sys.sql_dependencies.object_id

Msg 446, Level 16, State 9, Line 1
Cannot resolve collation conflict for replace operation.

What does this error message mean and how can it be resolved

Database is Latin1_General_CI_AI
sys.objects is Latin1_General_CI_AI
sys.sql_dependencies
is Latin1_General_CI_AI
child.name is nvarchar(128)
child.type is char(2)

Remove the child.type + and the query works.

Change the query to this and it fails:

select child.type + child.name
from sys.sql_dependencies
inner join sys.objects child
on child.object_id = sys.sql_dependencies.object_id

Msg 451, Level 16, State 1, Line 1
Cannot resolve collation conflict for column 1 in SELECT statement.



Answer this question

SQL 2005 collation conflict for replace operation

  • Nathan Franklin

    The error message is due to the fact that collation of name is SQL_Latin1_General_CP1_CI_AS and type is Latin1_General_CI_AS_KS_WS. So you need to use COLLATE clause to coerce say name column like:

    select child.type + child.name collate Latin1_General_CI_AS_KS_WS

    from sys.sql_dependencies

    inner join sys.objects child

    on child.object_id = sys.sql_dependencies.object_id



  • SQL 2005 collation conflict for replace operation