无法解决联合操作中latin1_general_ci_as和sql_latin1_general_cp1_ci_as之间的排序规则冲突

时间:2016-02-17 01:11:16

标签: sql collation

SELECT   
  f.feature_id,
  f.site_code,
  f.plot_number,
  'ID Error - 7th and 8th characters of ID do not match the Island of the selected Structure, expected value: ' + f.ward_code as message_text,
  'Y' as IsError
FROM feature f
  inner join feature_type ft on f.feature_type_code = ft.feature_type_code AND ft.feature_group_code IN ('FC')
WHERE f.ward_code <> RIGHT(LEFT(f.feature_id, 8),2)

union

SELECT  
  f.feature_id,
  f.site_code,        
  f.plot_number,
  'ID Error - Engineering District do not match the Region of the selected    Structure, expected value: '+ laa.region as message_text,
  'Y' as IsError
FROM feature f
  inner join feature_type ft on f.feature_type_code = ft.feature_type_code AND ft.feature_group_code IN ('FC')
  inner join loc_ase.loc_db.dbo.loc_admin_area laa on f.contract_area_code = laa.contract_area_code 
WHERE f.[area_code] collate SQL_Latin1_General_CP1_CI_AS <> laa.[region] collate SQL_Latin1_General_CP1_CI_AS 

1 个答案:

答案 0 :(得分:1)

您应该在其中一个排序规则中选择VARCHAR字段以避免此错误。一个例子:

CREATE TABLE #t1(some_text NVARCHAR(512) COLLATE latin1_general_ci_as);
CREATE TABLE #t2(other_text NVARCHAR(512) COLLATE sql_latin1_general_cp1_ci_as);

SELECT some_text FROM #t1
UNION
SELECT other_text COLLATE latin1_general_ci_as FROM #t2

DROP TABLE #t1;
DROP TABLE #t2;

这不会导致排序错误。将这种工作方式应用于您的查询。

相关问题