我在 SQL Server 2000 (v8.0.760) 中创建了一个视图,它使用外部连接连接多个表并使用 ISNULL、REPLACE 和 SUBSTRING 函数。该视图在该数据库上运行良好。数据库设置为整理 Latin1_General_BIN。
但是,当我尝试通过具有相同排序规则的 SQL Server 2008 R2 数据库上的链接服务器访问该数据时,失败并出现以下错误:
消息 8180,级别 16,状态 1,行 1
声明无法准备。
消息 446,级别 16,状态 8,第 1 行
无法解决子字符串操作的排序规则冲突。
我尝试了几件事,包括在我的视图上设置子字符串字段的排序规则,设置链接服务器选项排序规则兼容性 = True 和排序规则名称 = '空白',以及其他。
我可以通过链接服务器从其他表/视图中选择数据。创建视图的视图 SQL 是:
SELECT 'CRM' AS SYSTEM_SOURCE,
ISNULL(F.PARENT_REGION_ID,' ') AS REGION,
ISNULL(B.COMPANYID,' ') AS COMPANYID,
ISNULL(A.SO_ID,' ') AS SO_ID,
ISNULL(L.LINE_NBR,0) AS TIMESHEET_LINE,
isnull(H.NOTE_SEQ_NBR,0) AS NOTE_SEQ_NBR,
ISNULL(A.SERVICE_ID,' ') AS SERVICE_ID,
ISNULL(C.DESCR80,' ') AS DESCR80,
ISNULL(A.SO_STATUS,' ') AS SO_STATUS,
ISNULL(A.SO_PRIORITY,' ') AS SO_PRIORITY,
ISNULL(E.ASSETTAG,' ') AS ASSETTAG,
ISNULL(RIGHT(REPLICATE(' ', 18) + LTRIM(E.INST_PROD_ID), 18),' ') AS PRODUCT_ID,
ISNULL(G.NAME1,' ') AS NAME1,
ISNULL((CONVERT(CHAR(10),A.SO_DATE,121)),'') AS SO_DATE,
ISNULL((CONVERT(CHAR(10),A.START_DT,121)),'') AS ACTL_START_DATE,
ISNULL((CONVERT(CHAR(10),D.ACT_END_DATE,121)),'') AS ACTL_END_DATE,
ISNULL(A.ENS_MTR_TOTAL,0) AS ENS_MTR_TOTAL,
ISNULL(K.ENS_MTR_READING,0) AS ENS_MTR_READING,
ISNULL(I.ENS_MTR_TOTAL,0) AS ENS_MTR_TOTAL,
ISNULL(D.TOTAL_ACT_TIME,0) AS TOTAL_ACT_TIME,
ISNULL(A.ENS_IPROD_DWN_TIME,0) AS ENS_IPROD_DWN_TIME, ISNULL(A.ENS_RIG_DWN_TIME,0) AS ENS_RIG_DWN_TIME,
ISNULL(J.MODEL_NBR,' ') AS MODEL_NBR, ISNULL(J.PROD_BRAND,' ') AS PROD_BRAND,
ISNULL((CONVERT(CHAR(10),E.INSTALLED_DATE,121)),'') AS INSTALLED_DATE,
ISNULL(L.PERSON_ID, ' ') AS PERSON_ID,
ISNULL(L.DTL_TOTAL, 0) AS DTL_TOTAL,
ISNULL(SUBSTRING(D.ENS_PROBLEM_CD, 1, 15),' ') as PROBLEM_CD,
ISNULL(SUBSTRING(D.ENS_PRDCOMP_ID, 1, 15),' ') as PROBLEM_ID,
CASE
WHEN L.PERSON_ID = NULL THEN ' '
ELSE ISNULL((SELECT M.NAME FROM PS_RD_PERSON_NAME M WHERE M.PERSON_ID = L.PERSON_ID), ' ') END AS NAME,
(CONVERT(CHAR(10),SUBSTRING(CONVERT(CHAR,GETDATE(),121), 1, 10),121)) AS CUR_DATE,
ISNULL(REPLACE(H.SUMMARY_RF,'|',''),' ') AS NOTE_SUBJECT ,
ISNULL(REPLACE(REPLACE(REPLACE(CAST(H.DESCRLONG AS CHAR(8000)), CHAR(10),' '), CHAR(13), ' '),'|', ''),' ') AS NOTE_DETAIL
FROM PS_RF_SO_HDR A
, PS_RD_COMPANY B
, PS_RF_SERVICE C
, PS_RF_SO_LINE D
, PS_RB_REGION F
, PS_RF_PROVIDER_GRP G
, PS_RF_INST_PROD E
, PS_RF_SO_NOTE H
, PS_ENS_MTR_INST_PR I
, PS_PROD_ITEM J
, PS_ENS_MTR_SO_HDR K
, PS_RF_TIME_LINE L
WHERE A.BO_ID_CUST = B.BO_ID
AND C.SERVICE_ID = A.SERVICE_ID
AND A.BUSINESS_UNIT = D.BUSINESS_UNIT
AND A.SO_ID = D.SO_ID
AND B.COMPANYID *= F.REGION_ID
AND A.PROVIDER_GRP_ID *=G.PROVIDER_GRP_ID
AND A.INST_PROD_ID *= E.INST_PROD_ID
AND A.SO_ID *=H.SO_ID --AND 1 = '1'
AND A.INST_PROD_ID *= I.INST_PROD_ID
AND A.CUST_SETID *= J.SETID
AND A.PRODUCT_ID *= J.PRODUCT_ID
AND A.BUSINESS_UNIT = K.BUSINESS_UNIT
AND A.SO_ID = K.SO_ID
AND D.BUSINESS_UNIT *= L.BUSINESS_UNIT
AND D.TIME_SHEET_ID *= L.TIME_SHEET_ID