加入操作中的问题

Issue in join operation

我创建了如下代码行的存储过程

    ALTER PROCEDURE [dbo].[prJurisdictionFetchForAgentLicence]
@AgentId int
As
Declare @individual varchar(20) = null;

Create table #Split 
(
Jurisdiction nvarchar(max)
)
Insert into #Split select Jurisdiction from tbLicence where AgentId =@AgentId;

Select * from #Split;

DECLARE @products VARCHAR(MAX)='';

SELECT @products += Isnull(Jurisdiction, '') + ',' FROM   #Split;

SELECT right(@products,len(@products)-1); 

Create table #TempJurisdiction
(
JurisdictionX nvarchar(max)
);

Insert into #TempJurisdiction 
SELECT 
 Split.a.value('.', 'VARCHAR(MAX)') AS TempJurisdictiom
FROM  
(
SELECT CAST ('<M>' + REPLACE(@products, ',', '</M><M>') + '</M>' AS XML) AS CVS 
) AS A CROSS APPLY CVS.nodes ('/M') AS Split(a);

Select * from #TempJurisdiction;

SELECT L.Jurisdiction,
L.JurisdictionX
FROM   tbJurisdiction L
JOIN #TempJurisdiction P
ON P.JurisdictionX = L.JurisdictionX

执行此存储过程时抛出错误消息

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

您的排序规则应该相似,只需将 table 上的排序规则更改为 "less normal",而不是其他数据库 tables

select *
from table1
join table2 on (table1.field collate SQL_Latin1_General_CP1_CI_AS = table2.field)

举个例子。我的猜测是您的 tempDb 与您的 SP 所在的数据库具有不同的排序规则,这就是您遇到问题的原因 - 虽然只是猜测。

这是一篇与您的问题相关的博客post:http://blog.sqlauthority.com/2007/06/11/sql-server-cannot-resolve-collation-conflict-for-equal-to-operation/

基本上,您的一个排序规则状态为 "accent insensitive" (AI),而其他排序规则状态为 "accent sensitive" (AS) - 尝试比较不同排序规则之间的相等性,您可能会明白错误的原因将在不使排序规则相似的情况下被抛出。