I received the following error when I was attempting to compare columns in a SQL query between two tables located in two separate databases. In this case, the collation settings between the two databases were configured differently. Rather make any changes to the databases, I was able to apply a simple fix to my SQL query: In fact even when I changed the Collation in the Database it still did not Join!
ORIGINAL QUERY –
SELECT TOP (100) PERCENT dbo.MyLoans.LoanNumber AS [Loan Number], LoansDW.dbo.TAP.BorrFirstName AS [PB First], LoansDW.dbo.TAP.BorrLastName AS [PB Last]
FROM EncompassDW.dbo.TAP RIGHT OUTER JOIN
dbo.FiveStarLoans ON LoansDW.dbo.TAP.LoanNumber = dbo.FiveStarLoans.LoanNumber
ORDER BY [Loan Number]
FIX –
Simply apply the default collation to the fields you are comparing.
SELECT TOP (100) PERCENT dbo.MyLoans.LoanNumber AS [Loan Number], LoansDW.dbo.TAP.BorrFirstName AS [PB First], LoansDW.dbo.TAP.BorrLastName AS [PB Last]
FROM EncompassDW.dbo.TAP RIGHT OUTER JOIN
dbo.FiveStarLoans ON LoansDW.dbo.TAP.LoanNumber = dbo.FiveStarLoans.LoanNumber COLLATE DATABASE_DEFAULT
ORDER BY [Loan Number]