Tuesday, May 1, 2012

Collation conflict in T-SQL

Have you ever encounter a problem when working in T-SQL like, "Cannot resolve the collation conflict between "XX_90_CI_AI" and "SQL_Latin1_General_CP1_CI_AS" in the UNION operation." The reason for this error message is collation conflict has been occurred while SQL server trying to compare two columns or expressions which have different collations. This error cause most of the time when compare columns with a temporary table column, because other table columns are in the database default collation settings and temporary tables may not in the default collation. 

As I experienced to overcome this problem we can simply apply collation setting for the tempary table column with default collation settings as follows

Colname COLLATE DATABASE_DEFAULT from #temp

 

No comments:

Post a Comment