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

  • Josh Curtiss
    June 24, 2009 8:03 pm

    The error message is useless to help us know this is what we should do. But your tip is perfect. Thanks for the help.

    Reply
  • Thanks a lot!

    Reply
  • Hi!!!

    How can i use the COLLATE DATABASE_DEFAULT in this update

    update a set area = b.area from tbl_lnventas as a
    inner join [10.105.162.223].dbunica3.dbo.cat_entidad as b on b.codigolada = left(a.ctelefono,8)
    where a.area=”
    go

    Reply
  • Great solution. Solved my problem.

    Reply
  • Thanks a lot!!!
    Worked for me :)

    Reply
  • Hi i need a help with collation problem

    I am creating a database with sql_latin_general collation in an sql instance with collation latin_general.

    While running installed application error occurs.is there any way to handle this scenario.

    Please help me its very urgent

    Reply
  • Thanks a lot.
    It has saved lot of our time.
    Whew Superb!!!

    Reply
  • Thanks Pinalkumar, worked a treat for me.

    Thank God for forums and the people like you who give their expertise so freely and unselfishly.

    Reply
  • Freek Van Mensel
    July 31, 2009 1:48 pm

    Thanks a lot.
    It was very helpful for me.

    Reply
  • This work , very helpful to you
    It Realy Works !!!
    Thanks

    Reply
  • Thanks from me too!

    Reply
  • Gracias, muchas gracias.

    Reply
  • thanks admin

    Reply
  • Gosh, thanks. I hate this problem and I always forget the solution, so finally I’ve bookmarked this page.

    You’re a life saver. Nice to see a 2 year-old blog post bring satisfaction to so many!

    Reply
  • I just saw this and, from an educational perspective, want to say that the original statement at the top of this post has a syntax error in that it is missing the ON clause and therefore won’t compile.

    Having said that, the information contained therein was useful.

    Tony S.

    Reply
  • Excellent solution!!! this helped me to fix my problem

    Reply
  • Thanks, It solved my problem

    Reply
  • hi i was wondering if you can help. I am testing a script in SQL server 2000 (Query Analyzer) and everytime i am doin a runtime it gives me the following error:
    Cannot resolve collation conflict for equal to operation.

    my code is this

    select Count(distinct username) as Failed from

    (select Quiz.quizId,QuizAttachment.nodeID
    from Quiz,QuizAttachment,PolicySet
    where Quiz.quizID=QuizAttachment.quizID
    and QuizAttachment.nodeID=PolicySet.nodeID
    and Quiz.active=1)PartialQuizDetails

    any idea on how to resolve this? would most appreciate it

    Reply
  • oh and have to mention that my collation on my database that im using is on SQL_LATIN_GENERAL_CP1_CI_AS

    Reply
  • @Simar

    One issue is that the COUNT works on username, which is not a field in the SELECT clause of the sub-query.

    Reply

Leave a Reply