MS SQL归类冲突Latin1_General_CI_AS链接服务器

时间:2016-02-24 18:37:47

标签: sql-server tsql collation

所以我在发布之前做了一些阅读,并且能够解决大多数失败的作业的大部分校对冲突,但最后一个查询是代理作业中的3步中的1步;通过在联接上添加COLLATE子句,我能够解决其他2。

在这个查询中,它说的是INSERT语句中的冲突,但我知道实际的冲突可能是Select语句中的任何一个列......

这个新的链接服务器最近被迁移,我没有被带入循环,所以他们没有费心检查兼容性问题......或者真的测试任何东西......

COMPANY_SQL01是链接服务器,SQL Server 2014

Company_BRK是运行此代理作业步骤的主服务器,运行SQL 2008,但兼容性设置为SQL 2000(80)......

在尝试对各个查询进行故障排除之前,我进入链接服务器并将所有数据库更改为SQL_Latin1_General_CP1_CI_AS排序规则,只有单个列可能仍在Latin1_General_CI_AS ...

我从下面的查询中收到此错误: Msg 468,Level 16,State 9,Line 8 无法在等于操作的情况下解决“SQL_Latin1_General_CP1_CI_AS”和“Latin1_General_CI_AS”之间的排序规则冲突。

set transaction isolation level read uncommitted

declare @current as datetime = getdate()

delete from COMPANY_brk.dbo.COMPANY_ar_avg_days


insert into COMPANY_brk.dbo.COMPANY_ar_avg_days

select distinct cmp_id, sum(datediff(day, invdate, paydate))/count(invoicenum) 'avg_days'
from (
select dat_arobp.IDCUST as cmp_id,
CAST(SUBSTRING(CAST(dat_arobp.DATEBTCH AS CHAR(8)), 1, 4) 
                      + '-' + SUBSTRING(CAST(dat_arobp.DATEBTCH AS CHAR(8)), 5, 2) + '-' + SUBSTRING(CAST(dat_arobp.DATEBTCH AS CHAR(8)), 7, 2) AS smalldatetime) 
                      AS 'paydate', 
COMPANY_brk.dbo.invoiceheader.IVH_DELIVERYDATE AS 'invdate',
dat_arobl.IDINVC 'invoicenum'
from [COMPANY-SQL01].COMPANYdat.dbo.AROBL dat_arobl
inner join COMPANY_brk.dbo.invoiceheader on COMPANY_brk.dbo.invoiceheader.ivh_invoicenumber=dat_arobl.IDINVC
inner join [COMPANY-SQL01].COMPANYdat.dbo.AROBP dat_arobp on dat_arobp.IDMEMOXREF=COMPANY_brk.dbo.invoiceheader.ivh_invoicenumber
where dat_arobl.amtduetc=0 --and dat_arobp.DATERMIT<>'0'
and dat_arobp.IDINVC not in (select i.ivh_invoicenumber from COMPANY_brk.dbo.invoiceheader i)
and datediff(day, COMPANY_brk.dbo.invoiceheader.IVH_DELIVERYDATE, @current)<700
union
select usa_arobp.IDCUST as cmp_id,
CAST(SUBSTRING(CAST(usa_arobp.DATEBTCH AS CHAR(8)), 1, 4) 
                      + '-' + SUBSTRING(CAST(usa_arobp.DATEBTCH AS CHAR(8)), 5, 2) + '-' + SUBSTRING(CAST(usa_arobp.DATEBTCH AS CHAR(8)), 7, 2) AS smalldatetime) 
                      AS 'paydate', 
COMPANY_brk.dbo.invoiceheader.IVH_DELIVERYDATE AS 'invdate',
usa_arobl.IDINVC 'invoicenum'
from [COMPANY-SQL01].COMPANYusa.dbo.AROBL usa_arobl
inner join COMPANY_brk.dbo.invoiceheader on COMPANY_brk.dbo.invoiceheader.ivh_invoicenumber=usa_arobl.IDINVC
inner join [COMPANY-SQL01].COMPANYusa.dbo.AROBP usa_arobp on usa_arobp.IDMEMOXREF=COMPANY_brk.dbo.invoiceheader.ivh_invoicenumber
where usa_arobl.amtduetc=0 --and usa_arobp.DATERMIT<>'0'
and usa_arobp.IDINVC not in (select i.ivh_invoicenumber from COMPANY_brk.dbo.invoiceheader i)
and datediff(day, COMPANY_brk.dbo.invoiceheader.IVH_DELIVERYDATE, @current)<700
) as tbl
group by cmp_id

1 个答案:

答案 0 :(得分:1)

今天有这个工作!

在两个select语句的内部联接中,我必须为连接添加COLLATE SQL_Latin1_Gerenal_CI_AS,将主服务器与链接服务器进行比较,并为链接服务器添加COLLATE Latin1_General_CI_AS&gt;主服务器比较:

inner join company_brk.dbo.invoiceheader on 
company_brk.dbo.invoiceheader.ivh_invoicenumber=dat_arobl.IDINVC COLLATE SQL_Latin1_General_CP1_CI_AS

inner join [company-SQL01].flsdat.dbo.AROBP dat_arobp on 
dat_arobp.IDMEMOXREF=company_brk.dbo.invoiceheader.ivh_invoicenumber COLLATE Latin1_General_CI_AS

还必须在where子句中添加1:

and dat_arobp.IDINC COLLATE DATABASE_DEFAULT NOT IN (select ... )

查询速度非常慢,需要大约8分钟才能更新~2k行......但是就像永远这样,如果它没有被破坏......

/编辑:所以,如果我按原样运行它,查询工作正常,但如果尝试运行代理作业,同样的查询(第2步,共3步)就是在自己上创建一个LCK_M_U并且它甚至不会释放它20分钟后......还没有完全解决。