Search

Saturday, November 19, 2011

Collation Conflicts in a SQL Server Join

Today I got an error while running this query : 
SELECT TOP 20 * FROM AccountMaster AS A INNER JOIN GroupMaster AS G ON A.GroupName = G.GroupName
I got this Error:


I searched the net since I couldn’t remember the exact syntax for the clause. 
The solution is easy, add a COLLATE DATABASE_DEFAULT to the join condition to force a specific collation on the field. I could easily have added a COLLATE Latin1_General_CI_AS as well, but since I knew that the second field was database defaults, I did this:
SELECT TOP 20 * FROM AccountMaster AS A INNER JOIN GroupMaster AS G ON A.GroupName COLLATE DATABASE_DEFAULT = G.GroupName
Now this query worked fine.



No comments:

Post a Comment