sqlserver排序规则问题(Cannot resolve the collation conflict between “SQL_Latin1_General_CP1_CI_AS” and “Chinese_PRC_CI_AI” in the equal to operation)
在做C#项目时在本地开发环境没有出现问题,但是部署到测试环境时走到其中一个方法报了Cannot resolve the collation conflict between “SQL_Latin1_General_CP1_CI_AS” and “Chinese_PRC_CI_AI” in the equal to operation这个错误,但是该sqlserver数据库用的却是也是Chinese_PRC_CI_AI的排序规则,再次修改数据库的排序规则为Chinese_PRC_CI_AI也没有用。
解决办法:
在查询的时候设置排序规则
修改前代码:
select * from dbo.table1 temp
left join dbo.Table2 so
on temp.CityCode collate = so.[city_or_cg-1_code]
where temp.CityCode is null
修改后代码:
select * from dbo.table1 temp
left join dbo.table2 so
on temp.CityCode collate Chinese_PRC_CI_AI
= so.[city_or_cg-1_code] collate Chinese_PRC_CI_AI
where temp.CityCode is null
问题就解决了。
修改数据库的排序规则:
ALTER DATABASE [dbo]
COLLATE Chinese_PRC_CI_AI ;
GO