2
votes

When working with the Table1 and the Table2 or Table3 tables, I’m getting the following error

Microsoft SQL: Cannot resolve collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" in UNION ALL operator for DISTINCT operation.

DataBase Collation  is  SQL_Latin1_General_CP1_CI_AS    

Table1  Collation  is   SQL_Latin1_General_CP1_CI_AS    
Table2  Collation  is   SQL_Latin1_General_CP1_CI_AS
Table3  Collation  is   SQL_Latin1_General_CP1_CI_AS


SELECT
      b.[BudgetID]
      ,b.[Budget]
      ,b.[BudgetType]
      ,b.[BudgetStatus]
      ,b.[BudgetStartDate]
      ,b.[BudgetEndDate]
      ,b.[ActualStartDate]
      ,b.[ActualEndDate]
      ,b.[PlannedBudget]
      ,b.[ActualSpend]
      ,b.[ProductLineName]
      ,b.[ProductLineKey]
      ,b.[ProductName]
      ,b.[ProductKey]
      ,b.[PlannedLeads]
      ,b.[ActualLeads]

  FROM [dbo].[Table1]b
  inner join  [dbo].[Table2] c on c.budgetName = b.productlinename
  inner join [dbo].[Table3] p on p.productline = b.productlinename

Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" in the equal to operation.

2
ALTER TABLE, change collation. That error message indicates your collation usage is inconsistent. - jarlh
Possible duplicate of Cannot resolve the collation conflict between - user6695008
where is your UNION ALL operator as mentioned in error message ? - Yogesh Sharma
Tables don't have collations; instances, databases, and columns (same as database by default) have collations. One or more of the columns in your actual query have different collations. - Dan Guzman

2 Answers

1
votes

Just add COLLATE DATABASE_DEFAULT in both equal to operations and you are done. Collations can differ, not only on a DB level, but also on a column level. That's probably what's going on here.

0
votes

Add COLLATE to the JOIN syntax like so

  FROM [dbo].[Table1]b
  inner join  [dbo].[Table2] c on c.budgetName COLLATE SQL_Latin1_General_CP1_CI_AS = b.productlinename COLLATE SQL_Latin1_General_CP1_CI_AS 
  inner join [dbo].[Table3] p on p.productline COLLATE SQL_Latin1_General_CP1_CI_AS = b.productlinename COLLATE SQL_Latin1_General_CP1_CI_AS