运行以下程序后出现Collation错误。请有人在这方面帮助我。我试图在x3v64数据库中的两个模式之间进行整理。
开始
SELECT "SALESREP"."REPNUM_0", "SALESREP"."REPNAM_0",
"srheader" ."customercode" ,"srheader" ."customername" ,"ITMMASTER"."TSICOD_0",
"srdetail" ."productcode" ,"srdetail" ."productname" , "srdetail" ."packing" , "srdetail" ."stunit" ,"srdetail" ."unit", "ITMMASTER"."SAUSTUCOE_0",
"srheader" ."voucherdate" , "srheader" ."vouchernumber" , 1 AS "SNS_0",
"srdetail" ."site" ,"srheader" ."delcomment","srheader" ."vouchertype" ,"srdetail" ."unit" AS "TXNUNIT",
"srdetail" ."qty" , "srdetail" ."netrate" ,
"srdetail" ."grossamount" , "srdetail" ."discamt" , "srdetail" ."discamt" ,"srdetail" ."netamount" AS "LINEAMOUNT",'' as "SONUM","srheader" ."vouchernumber" as 'SR_NUM'
into #tmp_sal
FROM ("x3v64".dbo ."srheader" "srheader" INNER JOIN
"x3v64".dbo ."srdetail" "srdetail" ON "srheader" ."vouchernumber" ="srdetail" ."vouchernumber" ) INNER JOIN
"x3v64"."AUJANX3"."ITMMASTER" "ITMMASTER" ON "srdetail"."productcode" COLLATE SQL_Latin1_General_CP1_CI_AS ="ITMMASTER"."ITMREF_0" INNER JOIN
"x3v64"."AUJANX3"."SALESREP" "SALESREP" ON "srheader" ."srep" COLLATE SQL_Latin1_General_CP1_CI_AS = "SALESREP"."REPNUM_0"
UNION ALL
SELECT "SALESREP"."REPNUM_0", "SALESREP"."REPNAM_0",
"SORDER"."BPCORD_0", "SORDER"."BPCNAM_0","ITMMASTER"."TSICOD_0",
"SORDERP"."ITMREF_0","ITMMASTER"."ITMDES1_0", "ITMMASTER"."ITMDES3_0", "ITMMASTER"."STU_0","ITMMASTER"."SAU_0", "ITMMASTER"."SAUSTUCOE_0",
"SORDER"."ORDDAT_0", "SORDER"."SOHNUM_0", 1 AS "SNS_0",
"SORDER"."SALFCY_0","SORDER"."ICTCTY_0" As "Comments", 'SOI',"SORDERP"."SAU_0" AS "TXNUNIT",
"SORDERQ"."QTY_0", "SORDERP"."NETPRIATI_0",
"SORDERP"."GROPRI_0", "SORDERP"."DISCRGVAL2_0", "SORDERP"."DISCRGVAL3_0", ("SORDERP"."NETPRIATI_0" * "SORDERQ"."QTY_0") AS "LINEAMOUNT",'' as "SONUM","SORDER"."PJT_0" as 'SR_NUM'
FROM ((("x3v64"."AUJANX3"."SORDER" "SORDER" INNER JOIN
"x3v64"."AUJANX3"."SALESREP" "SALESREP" ON "SORDER"."REP_0"="SALESREP"."REPNUM_0") INNER JOIN
"x3v64"."AUJANX3"."SORDERP" "SORDERP" ON "SORDER"."SOHNUM_0"="SORDERP"."SOHNUM_0") INNER JOIN
"x3v64"."AUJANX3"."SORDERQ" "SORDERQ" ON ("SORDERP"."SOHNUM_0"="SORDERQ"."SOHNUM_0")
AND ("SORDERP"."SOPLIN_0"="SORDERQ"."SOPLIN_0")) INNER JOIN
"x3v64"."AUJANX3"."ITMMASTER" "ITMMASTER" ON "SORDERP"."ITMREF_0"="ITMMASTER"."ITMREF_0"
ORDER BY "srheader" ."vouchernumber"
select * from #tmp_sal
端
答案 0 :(得分:0)
您可以在第一个SELECT语句的JOIN条件中更改排序规则,以便您可以比较这些字段。但是您还需要更改选择列表中的排序规则,以便将它们插入到同一个临时表字段中。示例:
--this would fail with message "Cannot resolve collation conflict for column 1 in ORDER BY statement.".
SELECT ItemCode 'ItemCode'
FROM [SAP database].dbo.rdr1
UNION ALL
SELECT product 'ItemCode'
FROM [other database].dbo.[other table]
ORDER BY ItemCode
--this would succeed
SELECT ItemCode COLLATE DATABASE_DEFAULT 'ItemCode'
FROM [SAP database].dbo.rdr1
UNION ALL
SELECT Product 'ItemCode'
FROM [other database].dbo.[other table]
ORDER BY ItemCode
如果我从第一个SELECT语句中删除了ORDER BY子句,则会显示错误消息"无法解决SELECT语句中第1列的排序规则冲突。"。