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://blog.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!!!
Correct and Simple solution.
Good Work.
thanks
Can one of theese errors hang and a restart the SQLServerAgent service?
Thanks – Great Solution
Thanks… It solved my problem
Let me thank you in 2009.02.09
Great Solution.
[...] if you are looking for solution to SQL SERVER – Cannot resolve collation conflict for equal to operation visit [...]
Hi…. thank u so much …it’s really work for me :-)
Genius!
Thanks a lot!!!!
Helped me too when I was doing an update query.
I didn’t even know what collation was before this!
I get this error, when I add the clause, Expression type numeric is invalid for COLLATE clause.
I have added as :
ON tablename.Columnname COLLATE DATABASE_DEFAULT = tablename.columnname COLLATE DATABASE_DEFAULT
Worked for me. Simple solution.
thanks,
Murthi
Thanks,Simple Solution.
But how can i make the two tables to have same collation?
I don’t want to have different collation for tables.
How can i know a table/column’s collation?
God bless you. your solution is really good.
Thanks a lot.
thanks!
worked like a charm!
Its simply great. Thanks.
Thank you. Your solution saved me from hour of work.
Thanks! You saved my life!
Awesome… quick easy answer, saved us some time this morning! Thanks
Hey, we have one ready applicaion…it’s working fine in most of the customer but only one customer getting this error.
[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Cannot resolve collation conflict for equal to operation.
How to resolve this error with out chnage in code?
how to resolve this issue using SQL SERVER enterprise manager?
Regards / Sandeep
You saved my day. Thank!
Thanks a lot.
I had this problem and with this solution my query working fine.
A litlle diference between collates from diferent databases make this error.
Theres a one thing that I have doubt.
In my case I have 2 dbo’s
The firts have this COLLATE
SQL_Latin1_General_CP1_CI_AS
The other have this
Latin1_General_CI_AS
Whats the diference?
And theres a way to choose the right COLLATE in my query?
Sorry my english, I am brazilian…
Thanks again
I have collation error -’Cannot resolve collation conflict for equal to operation’ when calling a function that returns a table. The function is as below:
CREATE FUNCTION [dbo].[Split]
(
@RowData nvarchar(2000),
@SplitOn nvarchar(5)
)
RETURNS @RtnValue table
(
Id int identity(1,1),
Data NVARCHAR(10) NULL
)
AS
BEGIN
Declare @Cnt int
Set @Cnt = 1
While (Charindex(@SplitOn,@RowData)>0)
Begin
Insert Into @RtnValue (data)
Select
Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))
Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))
Set @Cnt = @Cnt + 1
End
Insert Into @RtnValue (data)
Select Data = ltrim(rtrim(@RowData))
Return
END
Then i added the server’s collation name as :
RETURNS @RtnValue table
(
Id int identity(1,1),
Data NVARCHAR(10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)
Then it is working fine. But i would like to know how to make this dynamic so that everytime the server’s collation property changes, i need not change the function.
for the above problem, i tried using database_default but it threw the same error. Is there anything like server_default?
Thank you for the help.
Yeah
The error message is useless to help us know this is what we should do. But your tip is perfect. Thanks for the help.
Thanks a lot!
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 solution. Solved my problem.
Thanks a lot!!!
Worked for 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 a lot.
It has saved lot of our time.
Whew Superb!!!
Thanks Pinalkumar, worked a treat for me.
Thank God for forums and the people like you who give their expertise so freely and unselfishly.
Thanks a lot.
It was very helpful for me.
This work , very helpful to you
It Realy Works !!!
Thanks
Thanks from me too!
Gracias, muchas gracias.
thanks admin
Gosh, thanks. I hate this problem and I always forget the solution, so finally I’ve bookmarked this page.
You’re a life saver. Nice to see a 2 year-old blog post bring satisfaction to so many!
Bill Dawson,
Thank you for your kind words!
Regards,
Pinal
I just saw this and, from an educational perspective, want to say that the original statement at the top of this post has a syntax error in that it is missing the ON clause and therefore won’t compile.
Having said that, the information contained therein was useful.
Tony S.
Excellent solution!!! this helped me to fix my problem
Thanks, It solved my problem
hi i was wondering if you can help. I am testing a script in SQL server 2000 (Query Analyzer) and everytime i am doin a runtime it gives me the following error:
Cannot resolve collation conflict for equal to operation.
my code is this
select Count(distinct username) as Failed from
(select Quiz.quizId,QuizAttachment.nodeID
from Quiz,QuizAttachment,PolicySet
where Quiz.quizID=QuizAttachment.quizID
and QuizAttachment.nodeID=PolicySet.nodeID
and Quiz.active=1)PartialQuizDetails
any idea on how to resolve this? would most appreciate it
oh and have to mention that my collation on my database that im using is on SQL_LATIN_GENERAL_CP1_CI_AS
@Simar
One issue is that the COUNT works on username, which is not a field in the SELECT clause of the sub-query.
Hi!!!
How can i use the COLLATE DATABASE_DEFAULT in this update
update dialer_campSource set iZonaHoraria = hh.tz_standard, iZonaHoraria_verano = hh.tz_daylight
from dialer_campSource cs inner join dialer_ccTimeZoneAreaMex hh
on
( len(cs.tel1) = 8 and @lada = hh.area and len(hh.area) = 2 )
or
( len(cs.tel1) = 7 and @lada = hh.area and len(hh.area) = 3 )
or
( len(cs.tel1) >= 10 and left(right(cs.tel1, 10), 3) = hh.area and len(hh.area) = 3 )
or
( len(cs.tel1) >= 10 and left(right(cs.tel1, 10), 2) = hh.area and len(hh.area) = 2 )
inner join inserted i
on cs.callout_id = i.callout_id
Thanks a lot. Good idea..
Great post brother, keep up the good work.
good!
Thanks a lot!!!
How can I use the Collate clause if I am matching say –
Select accountID from Table1
where AccountID in (select accountID from table2)
Very helpful, thank you!
Anu this worked fine for me:
“WHERE accountID COLLATE DATABASE_DEFAULT IN
(SELECT accountID COLLATE DATABASE_DEFAULT
FROM table2)”
Hi,
I am getting error ‘Cannot resolve collation conflict for equal to operation.’ while running below procedure.
I dont have much idea about sqlserver.
CREATE PROCEDURE [dbo].[SP_GETEXCHANGERATEFRMAMEX] AS
set xact_abort on
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
–BEGIN DISTRIBUTED TRANSACTION
DECLARE @DEFAULTCUR NUMERIC
SELECT @DEFAULTCUR=DEF_CUR_ID FROM OR_DEFAULTS
DECLARE @EX_CUR_ID NUMERIC
DECLARE @EX_TT_ID NUMERIC
DECLARE @EX_RATE NUMERIC(18,8)
DECLARE @EX_UpdatedBy NVARCHAR(50)
DECLARE @EX_UpdatedOn DATETIME
DECLARE EXCURSOR CURSOR FOR
SELECT V_EXC_FRM_CCY AS EX_CUR_ID, TT_ID AS EX_TT_ID, N_EXC_SLS_DFL AS EX_RATE, ‘AMEX’ AS EX_UpdatedBy,
D_UPD_DAT AS EX_UpdatedOn FROM AMEXORA..AMEXHO.TBL_CCY_EXC_MST INNER JOIN OR_TRANSACTIONTYPE
on v_exc_frm_ccy_typ=TT_AMEX_REF WHERE CONVERT(NVARCHAR(10),V_EXC_TO_CCY) + ” + CONVERT(NVARCHAR(10),V_EXC_TO_CCY_TYP)
NOT IN (SELECT CONVERT(NVARCHAR(10),EX_CUR_ID) + ” + CONVERT(NVARCHAR(10),TT_AMEX_REF) FROM OR_EXCHRATE INNER JOIN
OR_TRANSACTIONTYPE ON TT_ID=EX_TT_ID WHERE EX_CUR_ID=@DEFAULTCUR) AND V_EXC_TO_CCY = @DEFAULTCUR and v_exc_to_ccy_typ = 0 AND V_EXC_RT_OPR = ‘M’
order by V_EXC_FRM_CCY, TT_ID
FOR READ ONLY
OPEN EXCURSOR
FETCH NEXT FROM EXCURSOR INTO @EX_CUR_ID, @EX_TT_ID, @EX_RATE, @EX_UpdatedBy, @EX_UpdatedOn
WHILE @@FETCH_STATUS=0
BEGIN
IF EXISTS(SELECT * FROM OR_EXCHRATE WHERE EX_CUR_ID=@EX_CUR_ID AND EX_TT_ID=@EX_TT_ID)
UPDATE OR_EXCHRATE SET EX_RATE=@EX_RATE, EX_UpdatedBy=@EX_UpdatedBy, EX_UpdatedOn=@EX_UpdatedOn WHERE EX_CUR_ID=@EX_CUR_ID AND EX_TT_ID=@EX_TT_ID
ELSE
INSERT INTO OR_EXCHRATE (EX_CUR_ID, EX_TT_ID, EX_RATE, EX_UpdatedBy, EX_UpdatedOn) VALUES (@EX_CUR_ID, @EX_TT_ID, @EX_RATE, @EX_UpdatedBy, @EX_UpdatedOn)
if @@rowcount>0
print ‘Updated new Exchange Rate for currency ‘ + convert(nvarchar(10),@EX_CUR_ID) + ‘ – ‘ + convert(nvarchar(50),dateadd(Hour,4,getutcdate()))
FETCH NEXT FROM EXCURSOR INTO @EX_CUR_ID, @EX_TT_ID, @EX_RATE, @EX_UpdatedBy, @EX_UpdatedOn
END
CLOSE EXCURSOR
DEALLOCATE EXCURSOR
–COMMIT TRANSACTION
SET XACT_ABORT OFF
GO
Any idea how to resolve this issue..?
thanx… cool tip.. it really works 4 me
thanks for your good articles.
i benefit from your good articles in your site
and i wish that you have good luck
Thanks alot for the article. keep it up.
I am working on 2 database servers, and both have ‘SQL_Latin_general*’ collate.
But in one server, following query not works,
“WHERE temp1.accountID IN
(SELECT temp1.accountID FROM table2)”
error : Cannot resolve the collation conflict between “Latin1_General_CI_AS” and “SQL_Latin1_General_CP1_CI_AS” in the equal to operation.
It works for the following,
“WHERE #temp1.accountID COLLATE DATABASE_DEFAULT IN
(SELECT accountID COLLATE DATABASE_DEFAULT
FROM #temp2)”
Why this is happening,it complains that collate is ‘Latin_General*’ in the server… any ideas…
Hello!
Please, see the following query:
select p.[PdrString1] as NUM,
p.[PdrString2] as TONEID,
g.[6032_GlobalPromptsFile_Name] as TNAME,
convert(varchar,p.[PdrTime],20) as ADATE,
case when PdrString5 = ‘Script ID: 6118′ then PdrString4 COLLATE DATABASE_DEFAULT else s.des end as DES,
p.[PdrString5] as STATUS,
case when PdrString5 = ‘Script ID: 6118′ then ‘Manual’ else s.aname end as ATYPE,
p.[PdrString3] as CATID, r.[9181_CosName]
from dbo.[PDR-2009-05-23] p
left outer join [105-02-agg.bakcell.com].cdr.dbo.frbt_status s on s.code = p.[PdrString5] COLLATE DATABASE_DEFAULT and s.atype = p.[PdrString4] COLLATE DATABASE_DEFAULT,
[105-02-agg.bakcell.com].magnolia.dbo.GlobalPromptsFiles g, [105-10-rep].magnolia.dbo.SubsPPS v, [105-10-rep].magnolia.dbo.COS r
where p.pdrtype = 3
and p.[PdrString3] = g.[6050_GlobalPromptsCategory_Id]
and p.[PdrString2] = [6031_GlobalPromptsFile_Code] COLLATE DATABASE_DEFAULT
and v.[9061_SubsNumber]=p.[PdrString1]
and v.[9180_CosId]=r.[9180_CosId]
order by PdrTime desc
Oh, I found the solution. Thanks a lot!
Thanks Mr.Pinal,
i am feeling lucky,
and also feel more jealous on your knowledge ;)
whatever problem i face in sql server ,
you provide me a solution, Great….
Hello!
Could you help me to figure that out:
select count(distinct a.[9060_SubsId])
from ([CDR-OCT-2009].dbo.[CDR_Oct2009],
[CDR-NOV-2009].dbo.[CDR_Nov2009]) a
where ChargeableDuration>’0′
and OriginateTime BETWEEN ‘2009-11-01′ and ‘2009-11-18 23:59′