Scenario :
这个问题是我的存储过程中用到临时表时发生的。
应该是sql server 服务器的排序规则 (SQL_Latin1_General_CP1_CI_AS )
与数据库的排序规则(Chinese_PRC_CI_AS)不同导致的吧。

Solution :
在创建临时表时在相应的字段定义加上Collate Database_Default ,问题就解决了。

如下:

USE [JointFrame2]
GO
/****** Object: StoredProcedure [dbo].[Proc_enterprise_unified_sam] Script Date: 2016/10/28 10:23:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--此存储过程将名称相似度大于80%的数据的主子记录标识设置为初始值
ALTER PROCEDURE [dbo].[Proc_enterprise_unified_sam]
AS
--=============================================================================== BEGIN
DECLARE
@id VARCHAR(40), --记录ID
@psname VARCHAR(220), ---污染源名称
@region_code VARCHAR(20), --污染源区域编码
@i BIGINT --记录执行
set @i = 0
--创建临时表,用于存放相似度大于80%的数据
create table #temp1(
    --加上COLLATE datebase_default NULL是为了避免此错误
id varchar(50) COLLATE database_default NULL
)
-- 定义游标.
DECLARE mycursor CURSOR FOR
--查找出未统一的污染源信息的区域编码和污染源名称
select id,region_code,psname from t_unified_enterprise_info where main_or_child = 1 and system_source != 0
--打开游标
OPEN mycursor
--填充数据
FETCH NEXT FROM mycursor INTO @id,@region_code,@psname
--判断游标的状态
-- 0 fetch语句成功
---1 fetch语句失败或此行不在结果集中
---2 被提取的行不存在
WHILE @@FETCH_STATUS = 0
BEGIN
set @i = @i + 1
print @i insert into #temp1
select id from (
select * from (
SELECT id,psname,dbo.FN_Resemble(@psname,psname) as a1,dbo.FN_Resemble(psname,@psname) as b1
FROM [dbo].[t_unified_enterprise_info] where region_code =@region_code)u where u.a1>=0.6) uu
where (uu.a1+uu.b1)/2>0.8 --如果相似度大于80%的数据在临时表中的条数大于1,则将他们全部置为初始值 if((select count(id) from #temp1)>1)
BEGIN
update t_unified_enterprise_info set main_or_child = 0,parentid = NULL,unique_code = NULL where system_source != 0 and id in (select id from #temp1)
END
delete from #temp1
--用游标去取下一行记录
FETCH NEXT FROM mycursor INTO @id,@region_code,@psname
END
--关闭游标
CLOSE mycursor
--删除游标
DEALLOCATE mycursor
END --exec [Proc_enterprise_unified_sam]

比较相似度的函数:

点击查看

Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Chinese_PRC_CI_AS" in the equal to operation.的更多相关文章

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

    ErrorMessage Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" ...

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

    Executed as user: NT AUTHORITY\SYSTEM. Cannot resolve the collation conflict between "Chinese_P ...

  3. sql server 小技巧(6) Cannot resolve the collation conflict between "Latin1_General_CI_AI" and "Chinese_PRC_CI_AS" in the equal to operation

    今天查询二个db,出现这个错误,二种方法,一种是把db里的collation改成一样的:如果不方便可以直接在sql语句后面转一下: select * from table where crm_mscr ...

  4. sql server Cannot resolve the collation conflict between "Chinese_PRC_BIN" and "Chinese_PRC_CI_AS" in the equal to operation

    今天查询二个db,出现这个错误,二种方法,一种是把db里的collation改成一样的:如果不方便可以直接在sql语句后面转一下: select * from table where crm_mscr ...

  5. conflict between "Chinese_PRC_CI_AI" and "Chinese_PRC_CI_AS" in the equal to operation

    在SQL SERVICE做关联查询的时候遇到了"conflict between "Chinese_PRC_CI_AI" and "Chinese_PRC_CI ...

  6. SQL Server, Cannot resolve the collation conflict

    今天遇到一个较为头痛的问题: Cannot resolve the collation conflict between "Chinese_PRC_90_CI_AS" and &q ...

  7. 解决SQL Server的cannot resolve the collation conflict问题

    当没有牵涉到两个不同的数据库时,出现以上错误.   Cannot resolve the collation conflict between "Chinese_PRC_CI_AS" ...

  8. Cannot resolve the collation conflict between "Chinese_PRC_CI_AS" and "SQL_L及由于排序规则不同导致查询结果为空的问题

    报错:Cannot resolve the collation conflict between "Chinese_PRC_CI_AS" and "SQL_L 出错原因: ...

  9. Cannot resolve collation conflict between "Chinese_Taiwan_Stroke_CI_AS" and "Chinese_PRC_CI_AS" in UNION ALL operator occurring in SELECT statement column 1.

    Cannot resolve collation conflict between . 解决方案: COLLATE Chinese_PRC_CI_AS 例子: SELECT A.Name FROM A ...

随机推荐

  1. 初始AngularJS

    <!-- AngularJS 通过 ng-directives 扩展了 HTML. ng-app 指令定义一个 AngularJS 应用程序. ng-model 指令把元素值(比如输入域的值)绑 ...

  2. iframe自适应高度的多种方法方法小结(转)

    对于自适应高度的代码有很多,可效率什么的考虑进来好代码就不多见了,不过思路倒是差不多的不带边框的iframe因为能和网页无缝的结合从而不刷新页面的情况下更新页面的部分数据成为可能,可是 iframe的 ...

  3. 在Win8上安装pyinstaller打包python成为可执行文件

    首先我使用的电脑系统是: Windows-8-6.2.9200 Python的版本是: 2.7.8 默认已安装python2.7且设置好了环境变量. 仅为个人记录,非教程. 首先先安装pip: 首先先 ...

  4. FastReport.net 使用记录

    FastReport.net  打印设计功能非常强大,打印内容可以自己设计.数据源可以来至许多个表,打印设计后的表格数据是以二进制保存在数据库中的. 1.打印设计: private void Desi ...

  5. UML_静态图

    类图        类图是描述类,接口,协作以及它们之间关系的图,用来显示系统中各个类的静态结构.类图是定义其他图的基础,在类图的基础上,可以使用状态图,协作图,组件图和配置图等进一步描述系统其他方面 ...

  6. KMP算法java实现

    /** * 假设现在文本串S匹配到 i 位置,模式串P匹配到 j 位置 如果j = -1,或者当前字符匹配成功(即S[i] == * P[j]),都令i++,j++,继续匹配下一个字符: 如果j != ...

  7. ios中strong, weak, assign, copy

    copy 和 strong(retain) 区别 1. http://blog.csdn.net/itianyi/article/details/9018567 大部分的时候NSString的属性都是 ...

  8. 实际用户ID,有效用户ID和设置用户ID

    摘自http://blog.csdn.net/guosha/article/details/2679334 实际用户ID,有效用户ID和设置用户ID 看UNIX相关的书时经常能遇到这几个概念,但一直没 ...

  9. 如何使用TestFlight进行App构建版本测试(转)

    在日常的开发当中,当一个项目在开发过程中或者完成准备上线,都需要我们进行真机测试,否则不可能开发完了就直接扔到了App,等上线了再下载看看,这都是不可能的.那么说到真机测试,大家肯定会想到弄一个99美 ...

  10. public void Delete<T>(List<T> EntityList) where T : class, new() 这是什么意思

    就是说T必须是一个类(class)类型,不能是结构(structure)类型. 这是类型参数约束,.NET支持的类型参数约束有以下五种: where T : struct                ...