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

  • Marvin Schmidt
    April 27, 2012 5:08 pm

    Hey Pinal

    I works, but i have issues with danisk special characters like æ ø Ã¥ they get converted to char like ‘ > †

    the databases are using Danish_Norwegian_CI_AS SQL 2008 and the other is SQL_Scandinavian_CP850_CI_AS SQL 2005

    Can you help…

    Reply
  • Easiest online solution I’ve ever found. Thanks!

    Reply
  • thanx

    Reply
  • That was really helpful! Thanks a lot!

    Reply
  • Giuseppe Knezovich
    May 29, 2012 12:24 pm

    You made some nice points there. I looked on the internet for the subject and found most people will consent with your blog.

    Reply
  • Paulo Cornélio
    June 6, 2012 9:59 pm

    superb

    Reply
  • glutenfreesql
    June 9, 2012 12:07 am

    Thanks

    Reply
  • Great…….It worked for me.

    Reply
  • marcoa_escalante
    June 12, 2012 9:41 pm

    excellent !!

    Reply
  • Hey pinal,

    Thanks for the solution

    Reply
  • Dejan Miklavcic
    June 19, 2012 7:58 pm

    You are a genious :D !!!!!

    Reply
  • Hello Pinal,

    Thanks for the Solution….

    Reply
  • Re: Msg 468, Level 16, State 9, Line 3
    Cannot resolve the collation conflict between “German_PhoneBook_CI_AS” and “SQL_Latin1_General_CP1_CI_AS” in the equal to operation.

    It may be of interest the “best practice” numeric sql construct (also on joins) avoids collation conflicts between user-defined and system databases. Example: the following numeric “in” statement is successful between the German_PhoneBook_CI_AS and SQL_Latin1_General_CP1_CI_AS collations:

    select DatabaseName from VersionDef
    where VersionCode = N’10.0.1.4540′
    and DatabaseSID in (
    select database_id
    from sys.databases
    where name = DB_NAME()
    )

    Reply
  • Hi All,
    One of our mappings in ODI generating code which will hit MS Sql 2008. I am getting the same error. In my case, I can not change the code generated by ODI tool. I have to make sure that the two tables/columns have the same collation.
    How can i achieve that without interrupting any other databases/data ?
    Could you help asap.

    Reply
  • IA AM GETTING ERROR WHILE RUN FOLLOWING STATEMENT

    UPDATE Kept_Report_Master
    SET [DESCRIPTION]=DISP_TAB.[DESCRIPTION],
    DISP_CLASS=DISP_TAB.CLASS
    FROM Kept_Report_Master
    INNER JOIN DISP_TAB
    WHERE Kept_Report_Master.DISPOSITION_CODE = DISP_TAB.DISP_CODE

    Reply
  • Thank you very much. You save my time again!!

    Reply
  • Thanks very much!

    Reply
  • Maria J. Santos
    September 5, 2012 6:53 pm

    Thank you. Your help is always apreciated :)

    Reply
  • Thank You, It was very informative.

    Reply
  • Pinal Dave – You are an international treasure. Once again you get me out of a tight spot with a quick, reliable and straightforward solution. I am (and not for the first time) very much in your debt. Abundant thanks.

    Reply

Leave a Reply