Monday, April 23, 2012

collation conflict in SQL


Got this error when runing a select query in Test Server, while before it was working, and it still working in my development database.

Msg 457, Level 16, State 1, Line 1
Implicit conversion of varchar value to varchar cannot be performed because the collation of the value is unresolved due to a collation conflict.

because I cannot change the structure of the database then I have to find a way so the query can be run.

this is the thing I found in the net that works without changing your database structure.

you have to find the collition conflict field, then put this line infront the field.
collate database_default

for example:
select a.field1,b.field2 collate database_default as field2alias from Dbo.table1 as a
inner join db1.dbo.tbl21 as b on b.field1 = a.field1
union all
select a.field1,b.field2 as field2alias from Dbo.table1 a
inner join db2.dbo.tbl2 as b on b.field1 = a.field1


and it works!
 -julie-

0 comments:

Post a Comment