我在SQL Server 2000(v8.0.760)中创建了一个视图,该视图使用外连接连接多个表,并使用ISNULL,REPLACE和SUBSTRING函数。该视图在该数据库上正常工作。数据库设置为collation Latin1_General_BIN。
但是,当我尝试通过SQL Server 2008 R2数据库上的链接服务器访问该数据并使用相同的排序规则时,会失败,并显示以下错误:
Msg 8180,Level 16,State 1,Line 1
声明无法准备 Msg 446,Level 16,State 8,Line 1
无法解决子字符串操作的排序规则冲突。
我尝试过多种方法,包括在我视图的子字符串字段上设置整理,设置链接服务器选项Collation Compatibility = True和Collation Name =' blank'以及其他。
我可以通过链接服务器从其他表/视图中选择数据。用于创建视图的视图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
答案 0 :(得分:1)
“努力减少查询”?
对不起,你真的没有认识到我们不知道这个查询的功能要求是什么的事实。功能需求本身就决定了开发工作,也就是说,除非你说他在编写SQL方面的技能不足。有趣的是,你没有提供真正有建设性的批评,这表明你对这种情况有了比他更好的理解以及完成他的SQL所需的代码。没有魔法修复来纠正他的问题。相反,你侮辱了他的专业知识。
但是等等,你不知道功能要求,对吗?
也许当你真的可以提供一些有用的回复时,它会更受欢迎。同时,在你的腰带,初中几年。当您作为开发人员真正处理数百万行企业级企业数据库时,请回复我。我相信你不会像上面提到的那样批评这么狡猾的答案。
你真的,
Flynn Kinkade