无法解决排序规则冲突 - SQL Server 2008 R2 SP1

时间:2015-10-07 09:08:30

标签: sql-server-2008-r2 collation

我试图运行以下查询:

SELECT [id]
      ,[company_id]
      ,[entry_no_]
      ,[project_no_sk]
      ,[project_no_]
      ,[task_code_sk]
      ,[task_code]
      ,[resource_code_sk]
      ,[resource_code]
      ,[work_type_code_sk]
      ,[work_type_code]
      ,[date_sk]
      ,[date]
      ,(SELECT  [Price]
        FROM    [helios_navision_data_mart].[dbo].[dim_resource_prices]
        WHERE   [Project No_]       = [project_no_]
        AND     [Work Type Code]    = [work_type_code]
        AND     [Task Code]     =   CASE WHEN [Task Code] IN (task_code) 
                                                    THEN task_code
                                        ELSE ''
                                    END
        ) as [Unit Price]
      ,[quantity]
  FROM [dbo].[fact_operational_time_entry]
  WHERE project_no_ = 'CHM-001'
  AND [chargeable] = 'Yes'
  AND [approved] = 'No'

但是在执行此查询时,我收到错误:

Msg 468, Level 16, State 9, Line 17
Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CS_AS" and "Latin1_General_CS_AS" in the equal to operation.

我已检查过表格,数据库和服务器的整理,它们都有" Latin1_General_CS_AS"作为整理定义。 错误发生在WHERE子句的某处,但我不知道在哪里......因为整理是相同的。

有人有想法吗?请帮忙。

KR, 凯文

1 个答案:

答案 0 :(得分:1)

不知道为什么,但我不得不修改子查询,以便强制进行校对。

,(SELECT    [Price]
        FROM    [helios_navision_data_mart].[dbo].[dim_resource_prices]
        WHERE   [Project No_]       = [project_no_] COLLATE Latin1_General_CS_AS
        AND     [Work Type Code]    = [work_type_code] COLLATE Latin1_General_CS_AS
        AND     [Task Code]         =   (CASE WHEN [Task Code] IN ([task_code] COLLATE Latin1_General_CS_AS) 
                                                    THEN [task_code] COLLATE Latin1_General_CS_AS
                                                ELSE ''
                                        END)
        ) as [Unit Price]