问题
I am trying to create a procedure in SQL Server 2008R2 but it is showing this error
Cannot resolve the collation conflict between "Latin1_General_CI_AI" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.
The procedure that I have created is
CREATE Procedure Ps_Quiz_OnlineTest_QuestionsWithOptions_Get --'Ques1'
@Ques Varchar(8000)
As
Begin
Select
A.QuestionId,
A.QsnDesc,
A.CorrectOption,
B.OptionValue,
A.Marks,
(
Select QsnName
From Quiz_tblQsnsLimitMaster
Where QsnId = @Ques) QuesPaper,
(
Select Durationoftest
From Quiz_tblQsnsLimitMaster
Where QsnId = @Ques) QuesPaper
From
Quiz_tblQsnCreationMaster A,
Quiz_tblQsnCreationDetail B
Where
A.QuestionId = B.QuestionId
And A.QuestionId In (
Select QuestionIds
From FN_Question_Answers_Quiz(@Ques))
And B.QuestionId In (
Select QuestionIds
From FN_Question_Answers_Quiz(@Ques))
Order By
A.QuestionId,
B.OptionOrder
End
I tried to collate tables with different collations but it did not worked. How can I solve this.
回答1:
probably this might help, change your where condition like this
Where A.QuestionId COLLATE DATABASE_DEFAULT = B.QuestionId COLLATE DATABASE_DEFAULT
回答2:
Since you've mentioned that QuestionID in each table is varchar, it's probably the comparison between those. So at a guess, try changing the line:
Where A.QuestionId = B.QuestionId And
To the following:
Where A.QuestionId = B.QuestionId COLLATE SQL_Latin1_General_CP1_CI_AS And
I'd prefer it if you used proper join syntax for your tables - but that's for another day ;-)
回答3:
try use this, where fieldname COLLATE DATABASE_DEFAULT = secondfieldname COLLATE DATABASE_DEFAULT
this is working
回答4:
Just use the following syntax when joining tables with different collations,
where A.QuestionId collate SQL_Latin1_General_CP1_CI__AS = B.QuestionId collate
SQL_Latin1_General1_General_CP1_CI_AS
回答5:
To overcome this use the below code:
SELECT NAME
FROM sys.objects
WHERE NAME COLLATE DATABASE_DEFAULT NOT IN (SELECT TYPE
FROM sys.objects)
来源:https://stackoverflow.com/questions/18077815/cannot-resolve-the-collation-conflict-between-latin1-general-ci-ai-and-sql-la