SQL SERVER – Cannot Resolve Collation Conflict For Equal to Operation

Cannot resolve collation conflict for equal to operation.

SQL SERVER - Cannot Resolve Collation Conflict For Equal to Operation collationconflict-800x206

In MS SQL SERVER, the collation can be set at the column level. When compared to 2 different collation columns in the query, this error comes up.

SELECT ID
FROM ItemsTable
INNER JOIN AccountsTable
WHERE ItemsTable.Collation1Col = AccountsTable.Collation2Col

If columns ItemsTable.Collation1Col and AccountsTable.Collation2Col have different collation, it will generate the error “Cannot resolve collation conflict for equal to operation“.

To resolve the collation conflict add the following keywords around “=” operator.

SELECT ID
FROM ItemsTable
INNER JOIN AccountsTable
WHERE ItemsTable.Collation1Col COLLATE DATABASE_DEFAULT
= AccountsTable.Collation2Col COLLATE DATABASE_DEFAULT

Watch this quick video for resolution:

Collation can affect the following areas:

  1. Where clauses
  2. Join predicates
  3. Functions
  4. Databases (e.g. TempDB may be in a different collation database_default than the other databases some times)

Checkout following video how collation can change the order of the column:

Just like collation, there is another problem with SQL Server and that is related to Parameter Sniffing, I have written a detailed blog post about how the parameter sniffing can be resolved in SQL Server.

Here are some really good blog posts which you can read about parameter sniffing and how you can avoid the problem related to it.

Reference: Pinal Dave (https://blog.sqlauthority.com)

Best Practices, SQL Collation, SQL Error Messages, SQL Joins, SQL Scripts, SQL Server
Previous Post
SQL SERVER – Retrieve – Select Only Date Part From DateTime – Best Practice
Next Post
SQL SERVER – LEN and DATALENGTH of NULL Simple Example

Related Posts

381 Comments. Leave new

  • thank you very muck!
    good luck!

    Reply
  • Thanks for this wonderful trick….

    Reply
  • thank you broo

    Reply
  • Dear sir,
    i am muthukumar..i have a error when restoring databae in sql server 2005.And i hava taken the database backup in sql2008.
    The error message is
    The media family on device ‘G:\myproject\Insurance.BAK’ is incorrectly formed. SQL Server cannot process this media family.
    VERIFY DATABASE is terminating abnormally.
    please help me…

    Reply
  • There is very little to say after Alastair Vize’s “Pinal Dave – You are an international treasure.” May be only THANK YOU.

    Pinal please help me simplify

    In ragards to XXX_CI and XXX_CS do I undestand correctly that with XXX_CI “Three = ThREE” would be true. Respevtively with XXX_CS “three = ThRee” it would be false and only “Three = Three” it would be true?
    Also is this true in the cases of IF compare, Where clause, Join predicates etc.

    Reply
    • If the collation is XXX_CS, then “three=”ThRee” becomes false. This is application if you compare with anystring with that collation in IF statement also

      Reply
      • madhivanan – Thank youuuuuu. I could have tried to see it in practice but I would never be sure if this makes it a rule

  • Thanks a lot!!!

    Reply
  • Pinal, Please, please take a look at my question from Dec 30. and see if you can help me. You can just use yes or no 3 times and that would be all.

    Reply
  • Nazim Akber Ali
    January 29, 2013 7:47 pm

    Thanks It works for me

    Reply
  • ÇaÄŸlar Durgun
    February 25, 2013 1:58 pm

    Great, many thanks!!

    Reply
  • Pinal thank you very much, it really works, not just for each field, but it also works simply adding like a sentence at the end of the query. Greettings from Caracas-Venezuela

    Reply
  • Lakshmi Kiranmayi Y
    May 15, 2013 2:36 pm

    Thanks it worked.

    Reply
  • Pradip killedar
    May 16, 2013 8:48 pm

    Thanks…

    Pradip killedar
    Kolhapur

    Reply
  • Hi pinaldave,

    Am getting the error which mentioned below while executing some plsql,

    Cannot resolve the collation conflict between “SQL_Latin1_General_CP1_CI_AS” and “Latin1_General_CI_AI” in the UNION operation.

    So, what to do?. Please help me..

    Reply
  • Thanks Pinaldave, very helpful!!!

    Reply
  • Muchísimas gracias. Teníamos ya varios años con éste problema y gracias a tí lo pudimos resolver definitivamente

    Reply
  • thank you!

    Reply
  • Debadrita Datta
    August 8, 2013 2:21 pm

    Thanks. It was indeed very helpful.

    Reply
  • Satyam Kundula
    August 21, 2013 10:24 pm

    thank you , it saved my time a lot.

    Reply
  • Thanx Pinal, its really helpful.

    Reply
  • The !funny thing about SQL Server is that it reports collation error even if statements like this one:

    IF @recId IS NULL AND @labelId IS NULL

    Reply

Leave a Reply