zoukankan      html  css  js  c++  java
  • Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Chinese_PRC_CI_AS" in the equal to operation.

    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]

    比较相似度的函数:

    点击查看

  • 相关阅读:
    [置顶] 从零开始学C++之STL(二):实现简单容器模板类Vec(vector capacity 增长问题、allocator 内存分配器)
    HDU4607(求树中的最长链)
    java从文件中读取数据然后插入到数据库表中
    rcp(插件开发)插件B需要引用插件A中的jar包-如何处理依赖关系
    HDU 2084 数塔
    Object-c学习之路二(oc内存管理黄金法则1)
    android adb命令 unable to connect to 192.168.1.155:5555
    安装node.js / npm / express / KMC
    oracle断电重启之ORA-00600[4194]
    virtualbox虚拟机迁移出现"connot find device eth0"错误
  • 原文地址:https://www.cnblogs.com/shuilangyizu/p/6006797.html
Copyright © 2011-2022 走看看