This SQL Server error occurs when you’re comparing columns from different tables that have different collation settings.
Understanding the Collations
Let’s quickly review the meaning of what is a collation.
For example:
Latin1_General_100_CI_AIis a modern collation with version 100 sorting rulesSQL_Latin1_General_CP1_CI_ASis a legacy SQL Server collation
where :
CImeans Case InsensitiveAImeans Accent InsensitiveASmeans Accent Sensitive
Choose the solution based on whether you need a one-time fix (use COLLATE in query) or want to standardize your database (alter column collation).
Here are the solutions to solve the issue.
Use COLLATE in Your Query
Add COLLATE DATABASE_DEFAULT to one of the columns in your comparison:
|
|
If you want to permanently align the collations:
|
|
Existing Table vs. Temporary Table
When you can’t alter an existing table but you can control the temp table definition, you should match the temp table’s collation to the existing table’s collation.
Here’s how to define your temp table:
|
|
To Find Content Table’s Exact Collation
If you’re not sure which collation ExistingTable.Code uses, run this:
|
|
Then use that exact collation name in your temp table definition.
Alternative: Fix at Join Time
If you prefer not to change the temp table definition, you can still fix it in your query.
In my case, I stumbled on the problem with the join clause:
|
|
But defining the temp table with the correct collation upfront is cleaner and avoids needing COLLATE clauses throughout your queries.
Documentation
Reference: Microsoft Learn.
Follow me
Thanks for reading this article. Make sure to follow me on X, subscribe to my Substack publication and bookmark my blog to read more in the future.
Credits: Image from Microsoft Server