How to resolve the collation conflict

Any thing related to MS SQL Server, Microsoft SQL Server Management Studio and SQL code.
Post Reply
Admin
Site Admin
Posts: 8
Joined: Thu Sep 05, 2019 19:11
Location: England
Contact:

How to resolve the collation conflict

Post by Admin » Fri Sep 06, 2019 16:10

You can resolve the collation conflict by forcing the collation used in a query to be a particular collation
e.g. Latin1_General_CI_AI or DATABASE_DEFAULT

Code: Select all

SELECT A.MyColumn
FROM MyTableA A
INNER JOIN MyTableB B
ON A.MyColumn COLLATE Latin1_General_CI_AI = B.MyColumn COLLATE Latin1_General_CI_AI

Code: Select all

SELECT A.MyColumn
FROM MyTableA A
INNER JOIN MyTableB B
ON A.MyColumn COLLATE DATABASE_DEFAULT = B.MyColumn COLLATE DATABASE_DEFAULT
You can check the collation of each of your database like this:

Code: Select all

SELECT
 NAME, 
 COLLATION_NAME
FROM sys.Databases
 ORDER BY DATABASE_ID ASC

Post Reply