Cannot resolve collation conflict for equal to operation.
In MS SQL SERVER, the collation can be set in column level. When compared 2 different collation column 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 following keywords around “=” operator.
SELECT ID
FROM ItemsTable
INNER JOIN AccountsTable
WHERE ItemsTable.Collation1Col COLLATE DATABASE_DEFAULT
= AccountsTable.Collation2Col COLLATE DATABASE_DEFAULT
Collation can affect 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)
Reference : Pinal Dave (http://www.SQLAuthority.com)






Thank you!! It really works!!
Thanks for the solution
thanks for that! it really helped me
Thanks a lots for simple and easy answer.
Agreed. Very helpful.
Grerat!
Thanks a lot. Its very helpful to resolve the problem.
Thanks a lot. That was quick and simple answer.
Thank’s! The Best Solucion!
Thanks for the help, I am still having a problem though maby i am being stupid. in my case i have a union select. see example
select top 10 ‘Listings’ as SearchItem , id as SearchResultID ,’Listings.aspx’ as PageToLoad ,Description as SearchDetail from StudentDirectoryItems
where Description like ‘%’ + @SearchValue + ‘%’ or Address like ‘%’ + @SearchValue + ‘%’ or PhoneNumbers like ‘%’ + @SearchValue + ‘%’ and VarsityID = @VarsityID
union
select top 10 ‘News’ as SearchItem , News.id as SearchResultID ,’HomePageNews.aspx?newsID’ as PageToLoad , News.ShortDescription as SearchDetail from News
left outer JOIN VarsityNews ON News.ID = VarsityNews.NewsID
where News.ShortDescription COLLATE DATABASE_DEFAULT like ‘%’ + @SearchValue COLLATE DATABASE_DEFAULT + ‘%’ or News.DisplayDescription COLLATE DATABASE_DEFAULT like ‘%’ + @SearchValue COLLATE DATABASE_DEFAULT + ‘%’ and VarsityNews.VarsityID = @VarsityID
union
Your help will be much appreciated.
Gareth,
change your code like :
where News.ShortDescription COLLATE DATABASE_DEFAULT like ‘%’ + @SearchValue + ‘%’ COLLATE DATABASE_DEFAULT or
Regards,
Pinal Dave (http://www.SQLAuthority.com)
Thanks! It worked
Hi Pinal
i have the following query:
SELECT
Site.Site__ID,
Site.Site_Type,
Site.Site_Post_Code,
Site.Site_Town,
Site.Site_PhaseName,
Site.Site_Name,
Office.Office__ID,
Office.Office_Type,
Office.Office_Status,
Office.Office_Name,
[User].User_Organisation,
[User].User_PhaseName,
[User].User_FullName,
[User].User_EmailAddress
FROM Site WITH (NOLOCK)
LEFT JOIN
Site_SiteToOffice ON Site.Site__ID = Site_SiteToOffice.Site__ID
LEFT JOIN
Office ON Site_SiteToOffice.__Office__ID = Office.Office__ID
LEFT JOIN
Office_OfficeToUser ON Office.Office__ID = Office_OfficeToUser.Office__ID
LEFT JOIN
[User] ON Office_OfficeToUser.__User__ID = [User].User__ID
LEFT JOIN
Site_SiteToUser ON Site.Site__ID = Site_SiteToUser.Site__ID AND [User].User__ID = Site_SiteToUser.__User__ID
where
(len (@CompanyName_key)=0 OR Office_Name COLLATE DATABASE_DEFAULT like @CompanyName_key )
AND (len (@UserName_key)=0 OR User_FullName COLLATE DATABASE_DEFAULT like @UserName_key )
AND (len (@UserEmail_key)=0 OR User_EmailAddress COLLATE DATABASE_DEFAULT like @UserEmail_key )
AND (len (@SiteName_key)=0 OR Site.Site_Name COLLATE DATABASE_DEFAULT like @SiteName_key )
Although i have placed the collate database_deafault i still get the error? any suggestions?
neddless to say that the parameters where decalred earlier on etc.
thanks!
Chingón!
Very Helpful….thanks.
This work , very helpful
Thanks
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
Great help! I ran into an issue with a case statemen and found an answer that might be helpful to someone else. Looked up “Collation Precendence” in books online and found a quick solution to a problem I don’t have time to fix the root cause for:
SELECT (CASE WHEN id > 10 THEN GreekCol ELSE LatinCol END) COLLATE DATABASE_DEFAULT
FROM TestTab
[...] 30th, 2007 by pinaldave This article is written based on feedback I have received on SQL SERVER - Cannot resolve collation conflict for equal to operation. Many reader asked me how to find collation of current database. There are two different ways to [...]
Thanks a lot!
Thanks for your advice with the collation error, it saved us lot of time.
Eersteklas!
Works like a charm!
Gracias, me saco del problema
Thank!!!
let me be # 27 to say thanx…
Thanks dude -you’ve made life easier!
Thanks!!!
Thanks a lot. !!!
Great help!
Googled “Cannot resolve collation conflict for equal to operation” and the first hit was this perfect solution!
Many Thx!
Hi,
I got the errros below, did anyone know about it?
Expression type int is invalid for COLLATE clause
Thanks
Thank you so much! Nice and easy solution!
Thanks!!! It Realy Works !!!
Thanks! This worked well for a database move I’m working on. I needed to concatenate a bunch of obsolete fields to dump into another new field. Here’s my example:
select
‘varchar_field1: ‘+varchar_field1+’
varchar_field2: ‘+varchar_field2+’
varchar_field3: ‘+varchar_field1+’
text_field1: ‘+cast(text_field1as varchar(800)) COLLATE DATABASE_DEFAULT
from my_table
Without collate database_default, I’d get this error:
Cannot resolve collation conflict for column 1 in SELECT statement.
Great… Going live with a major project and this little gem was a sweet, quick and perfect resolution
Cheers
Superb!!! Thank you!
hi
i too face this problem and found that the collation of one of the database is different. now i want to make the collation same. can i change the collation of an existing database and will it update collation for all existing tables and columns of that database.
Thank you,
Really appreciate it.
This work , very helpful to you
It Realy Works !!!
Thanks
Wow this works but just wondering why it works?
Thanks
Thanks a lot
HI Mr. Pinal Dave, such a great help, the collation problem wasnt there o the query i sent earlier, bacause that was incomplete…
the complete query plus the solution:::
set @str = ’select t0.docnum as SORefNo, t0.DocDueDate as SODocDueDate, t0.cardCode as CustomerCode, t7.cardName as CustomerName,
t1.itemcode as ItemCode, t4.ItemName as ItemName, t5.WhsName as WareHouseName, t6.U_NAME as UserName,
t1.quantity as SOQty, t2.quantity as SIQty,
case
when t1.quantity<=t2.quantity then 0 else t3.quantity
end as DraftSIQty, t1.quantity - t2.quantity as ”BackOrder”
from ordr t0 inner join
rdr1 t1 on t0.docentry=t1.docentry inner join
ocrd t7 on t0.CardCode=t7.CardCode inner join
ousr t6 on t0.Usersign=t6.UserId inner join
oitm t4 on t1.itemcode=t4.itemcode left join
owhs t5 on t1.Whscode=t5.Whscode left join
(select t10.draftkey, t11.baseentry, t11.baseline, t11.quantity from
oinv t10 inner join inv1 t11 on t10.docentry=t11.docentry) t2 on
t2.baseentry=t1.docentry and t2.baseline=t1.linenum left join
drf1 t3 on t3.baseentry=t1.docentry and t3.baseline=t1.linenum and (t2.draftkeyt3.docentry or t2.quantity is null)
where (t0.docduedate between ”’+convert(varchar(20),@startDate,102)+”’ and ”’+convert(varchar(20),@EndDate,102)+”’ ) ‘
– @whsCode
if ( @whsCode ‘NULL’ )
Begin
SET @str = @str + ‘ and ( (t1.Whscode COLLATE DATABASE_DEFAULT in (Select Value from fnSplitter(”’+ @whsCode +”’) ) ) or (t1.Whscode COLLATE DATABASE_DEFAULT is null) )’
End
Else
Begin
SET @str = @str + ‘ and((t1.Whscode in (t1.Whscode)) or (t1.Whscode is null))’
End
SET @str = @str + ‘ and not(t2.quantity is null and t3.quantity is null) ‘
SET @str = @str + ‘ order by docnum ‘
exec (@str)
Mr.Pinal, ur such a genius, i want to be ur friend.. u may not be aware but u helped me already with a lot of things, ur articles was so useful…..thanks thanks for the solution… :D:D:D
Thanks a million for the blog post Pinal.
Very usefull stuff.
:)
Jean
Thanks a lottttttt!!!!! It worked!
HI Mr. Pinal Dave,
How can we change the collation of a column???
what r the different types of collation in MS Sql??
Please help me asp.
Thanks in advance…
HI Mr. Pinal Dave,
I want to find the list of those employees whose name starts with either A or B without using union query.
Thanks Pinal,
Saved me a lot of searching.
Jason ;-)
Could you please help, i get the collation error with this query:
SELECT *
FROM ctbl_ReplenishOrders RO
left JOIN #tbl_OutputOrdered OO ON RO.OrderDate = OO.OrderedDate AND RO.Itemcode COLLATE DATABASE_DEFAULT = COLLATE DATABASE_DEFAULT OO.ItemCode
WHERE OO.Itemcode IS NULL
Even though i am trying your collation solution, it seems still not to work. Can you please help?
Many thanks!marlene
wow, u r wonderful dude
PD - thanks for the post!
Marlene , try:
SELECT *
FROM ctbl_ReplenishOrders RO
left JOIN #tbl_OutputOrdered OO ON RO.OrderDate = OO.OrderedDate AND RO.Itemcode COLLATE DATABASE_DEFAULT = OO.ItemCode COLLATE DATABASE_DEFAULT
WHERE OO.Itemcode IS NULL
Thanks Pinal,
It works.
Excellent this worked perfectly. Thanks!!!
Very useful tip. Thanks, perfect answer!
Thanks. I had problem with temporary table in join and this was nice and easy fix!
Thanks so much for the tip! It was very helpful.
Gracias, salvaste mi dia XD.
Thank you saved my day XD.
Thankyou , really helped me.
It’s works! you kick ass dude
Thanks Pinal, that saved the day for me!
John
Hi dave….awesome….a solution made to look so simple for quite a complex problem (it was definetly complex for me…:)…thanks a ton
Very helpful! Thank you…
Great help. It really works. Great job.
that saved the day for me
Excellent - simple post and resolved my problem - much appreciated!!
Worked for me. Thanks for the post!
hey, thanks so much for posting this. it really helped me. so much. :D
thanks thanks thanks! :)
brill thanks, got me out of sticky jam
Great! Huge thank you! Regret that I haven’t found this earlier.
Wow man, it works. Very appreciate….
Great, it is a great help
Very good mate, thanks
I’m trying the following syntax:
SELECT count(*) FROM [f_matter] M (nolock) LEFT JOIN #Matter T ON M.matter_Num COLLATE SQL_Latin1_General_Pref_CP850_CI_AS = COLLATE SQL_Latin1_General_Pref_CP850_CI_AS T.Matter
Getting error “Incorrect syntax near ‘COLLATE’.”
Please help. What am I doing wrong?
Thanks
Thanks a million,. you are a lifesaver.
Simply Great help…….
Thanks a lot :-)
Thank you too much! It’s helpful!
Thanks a lot, it happend to me in a case statement.
Hello, Marvellous Dave….it really worked for me. Thank you very much.
Cheers :)
Great, strange issue i felt. Thanks for the solution.
thanks a lot..
thank you very very much..
Thank you very much! It is a great help!
thank you sir, you save my day ^^
Great solution from the original post… Thanks a lot
Thank you very much! It is a great help!
Cheers mate! :o)
Hi have the below query and cannot quite figure out where excatly to use the collation.
Can somebody please help:
INSERT INTO CRMSUBSCRIPTIONSV1_HITS(USER_LOGONNAME, USER_PASSWORD, ORDER_ORDERPRODUCTID, ORDER_HITSPURCHASED)
SELECT DISTINCT USER_LOGONNAME,USER_PASSWORD,ORDER_ORDERPRODUCTID,ORDER_HITSPURCHASED
FROM CRMSUBSCRIPTIONSV1 WHERE CRMSUBSCRIPTIONSV1.PRODUCT_ISHITBASED = ‘1′ AND NOT EXISTS
(SELECT USER_LOGONNAME,USER_PASSWORD,ORDER_ORDERPRODUCTID,ORDER_HITSPURCHASED
FROM CRMSUBSCRIPTIONSV1_HITS,CRMSUBSCRIPTIONSV1 WHERE
CRMSUBSCRIPTIONSV1.USER_LOGONNAME = CRMSUBSCRIPTIONSV1_HITS.USER_LOGONNAME AND
CRMSUBSCRIPTIONSV1.USER_PASSWORD = CRMSUBSCRIPTIONSV1_HITS.USER_PASSWORD AND
CRMSUBSCRIPTIONSV1.ORDER_ORDERPRODUCTID = CRMSUBSCRIPTIONSV1_HITS.ORDER_ORDERPRODUCTID AND
CRMSUBSCRIPTIONSV1.ORDER_HITSPURCHASED = CRMSUBSCRIPTIONSV1_HITS.ORDER_HITSPURCHASED)
GROUP BY ORDER_ORDERPRODUCTID,USER_LOGONNAME,USER_PASSWORD,ORDER_HITSPURCHASED
Thanks in advance.
Works!!!!!!!!!!!1
Thanks you very much sir. You’re the man!
Great! Worked!
Thank you very much…
Thank you.
Thanks Pinal!
I would like to add that use Collate with ‘IN’ clause also.
Have a look in my Query which I solved using collate for ‘IN’ clause.
SELECT DISTINCT top 100 PERCENT FT_TBL.product, FT_TBL.RSV_desc, FT_TBL.LIST_PRICE, FT_TBL.uom, KEY_TBL.RANK, PDoc.product AS PDocProduct,
FT_TBL.pgroup, FT_TBL.Special_Conditions, FT_TBL.shop_id, SUM([Order Contents].Qty) AS Sqty
FROM Products1 AS FT_TBL INNER JOIN
FREETEXTTABLE(Products1, *, ‘fuel pump’) AS KEY_TBL ON FT_TBL.ID = KEY_TBL.[KEY] LEFT OUTER JOIN
[Order Contents] ON FT_TBL.product COLLATE DATABASE_DEFAULT = [Order Contents].[Item Number] COLLATE DATABASE_DEFAULT
LEFT OUTER JOIN
(SELECT product
FROM ProductDocs
WHERE ([Shop ID] IS NULL)) AS PDoc ON FT_TBL.product COLLATE DATABASE_DEFAULT = PDoc.product COLLATE DATABASE_DEFAULT
WHERE (FT_TBL.shop_id IS NULL) AND (FT_TBL.car IN
(select DISTINCT [Car Type] FROM [Car Types]))
GROUP BY FT_TBL.product, FT_TBL.RSV_desc, FT_TBL.LIST_PRICE, FT_TBL.uom, KEY_TBL.RANK, PDoc.product, FT_TBL.pgroup, FT_TBL.Special_Conditions,
FT_TBL.shop_id
ORDER BY KEY_TBL.RANK DESC
thanks you very much for nice tips! Its save my day. :)
thanks you very much for nice tips!
(Ovo je bila nocna mora dosad - Hvala (Serbian) )
Thanks you very much, Greate.
Thanks Pinal.
It has helped me a lot.
YES !!!! THANK YOU VERY VERY MUCH
MERCI BEAUCOUP (French)
MECI EN PIL (FWI Creol)
:-D
Superb boss!!!!!!! thank u for ur knowledge sharing.
Thank you very much!
Its really works
Thank you very much
Thnaks for this Article. Really it helped me.
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
Thanks, very helpful!!!
Exactly what I needed, thanks.
Very tidy, saved me from my ALTER TABLE nightmare against an 30Gb db
Thanks!
Thanks !!!
This help me with this …
WHERE ESTADO_PROCESO COLLATE DATABASE_DEFAULT in (select string from dbo.fn_SplitStrings(@as_estados, ‘,’))
Thank you very much! Nice tip!
Worked like a charm, thanks man :)
Many Many Thanks :)
It worked out for me!!!!!!!!!!!!
Plz kip up the gud work.
Thanks, it works!
thank you baby
Hi guys
I have added the COLLATE DATABASE DEFAULT after my join clauses, now i get an error: Expression type int is invalid for COLLATE clause.
Here is the query, can someone please help??
SELECT
I.Name,
A.Name EventShortName,
ISNULL(F.Name, ”) GroupShortDisplay,
C.ParameterName,
D.WinningValue,
COUNT(EntrantID) TotalEntries,
CASE WHEN D.WinningValue = G.Pick THEN
COUNT(EntrantID)
ELSE
0
END CorretEntries,
CASE WHEN D.WinningValue G.Pick THEN
COUNT(EntrantID)
ELSE
0
END IncorrectEntries
FROM [Pikum.Web].dbo.Event A WITH (NOLOCK)
INNER JOIN [Pikum.Web].dbo.[EventParameter] B WITH (NOLOCK)
ON B.EventID = A.EventID COLLATE DATABASE_DEFAULT
INNER JOIN [Pikum.Web].[dbo].[Parameter] C WITH (NOLOCK)
ON C.ParameterID = B.ParameterID COLLATE DATABASE_DEFAULT
INNER JOIN [Pikum.Web].dbo.[PikumEventParameter] D WITH (NOLOCK)
ON D.EventParameterID = B.EventParameterID COLLATE DATABASE_DEFAULT
LEFT JOIN [Pikum.Web].dbo.EventCategoryGroup E (NOLOCK)
ON E.EventID = A.EventID COLLATE DATABASE_DEFAULT
AND E.EventCategoryGroupID = D.EventCategoryGroupID COLLATE DATABASE_DEFAULT
LEFT JOIN [Pikum.Web].dbo.CategoryGroup F (NOLOCK)
ON F.CategoryGroupID = E.CategoryGroupID COLLATE DATABASE_DEFAULT
INNER JOIN [Pikum.Web].dbo.[EntrantPick] G WITH (NOLOCK)
ON G.PikumEventParameterID = D.PikumEventParameterID COLLATE DATABASE_DEFAULT
INNER JOIN [Pikum.Web].dbo.Pikum I WITH (NOLOCK)
ON I.PikumID = D.PikumID COLLATE DATABASE_DEFAULT
WHERE PikumStatusID >= 7
AND UserPikumCreatorID = 1566
and pikumidentifier = ‘V7Y2A-D4F40′
GROUP BY
I.Name,
A.Name,
ISNULL(F.Name, ”),
C.ParameterName,
D.WinningValue,
G.Pick
Thank you!
worked like a charm, thanks….
Thanks, very helpful!!!