--删除重复数据
if exists (select 1 from @t6db..sysobjects where name ='UA_Chart' and xtype ='u')
DELETE FROM @t6db..UA_Chart WHERE ID IN(SELECT ID FROM @t6db..UA_Chart GROUP BY ID HAVING COUNT(*)>1)
GO
--name重复，这几条记录在852没有
DELETE FROM @t6db..Vouchers WHERE CardNumber IN('pp32','pp33','pp34','PP41','PP42','PP43')
GO
DELETE FROM @t6db..NB_VisibleField WHERE cTableName='nb_payment' AND cFieldName IN('收方单位')
GO
DELETE FROM @t6db..VoucherPrefabricate WHERE cContent='手工输入' AND CardNumber IN ('QM10','QM14','QM16')
GO
DELETE FROM @t6db..AA_Busobject WHERE cBusobid in ('14',N'15',N'16',N'17',N'01',N'07',N'02',N'05',N'09') AND iAuthType=2
GO
DELETE FROM @t6db..nb_visiblefield WHERE cTableName ='nb_payment' AND cFieldName='支付状态'
GO
    declare @mysql varchar(8000)
    declare @cclass varchar(2)

    declare rstTemp cursor forward_only for select citem_class from @t6db..fitem  
    where citem_class not in ('ch','97','98')
    open rstTemp
    fetch next from rstTemp into @cclass
    while   @@fetch_status=0
    begin 
       SET @mysql='if exists(select name from @t6db..sysobjects where name=''fitemss'+@cclass+'class'' and xtype=''u'')
       begin
       select * into @u8db..fitemss'+@cclass+'class FROM @t6db..fitemss'+@cclass+'class'
       
       SET @mysql=@mysql+'
       alter table @u8db..fitemss'+@cclass+'class add constraint PK_fitemss'+@cclass+'class primary key(I_id)
       end'
       exec (@mysql)
       SET @mysql='if exists(select name from @t6db..sysobjects where name=''fitemss'+@cclass+''' and xtype=''u'')
       begin
       select * into @u8db..fitemss'+@cclass+' FROM @t6db..fitemss'+@cclass
       
       SET @mysql=@mysql+'
       alter table @u8db..fitemss'+@cclass+' add constraint PK_fitemss'+@cclass+' primary key(I_id)
       end'
       exec (@mysql)
              
       fetch next from rstTemp into @cclass
    end
    close rstTemp
    deallocate rstTemp   
GO
--删除普及版不支持的模块启用信息
IF OBJECT_ID('@t6db..UA_Account_sub_Ex') IS NOT NULL
begin
DELETE @t6db..UA_Account_sub_Ex WHERE cSub_Id NOT IN(
'AA','AM','AS','GL','MR','WA','FA','AR','AP','FP','PU','SA','ST','IA','EA','FT','RE','JY','NB'
)
--处理下ia_fa 年结标志 修复错误数据，以避免无法升级至10.0后续版本
update a set bclosing =1 from @t6db..UA_Account_sub_Ex a 
		inner join @t6db..UA_Account_sub_Ex b on 
			a.csub_id=b.csub_id and a.iyear =b.iyear-1
		where a.iyear<>9999 and a.csub_id in ('fa','ia')
			and a.imodiperi=12
end
go
IF OBJECT_ID('@t6db..UA_holdauth_Ex') IS NOT NULL
begin
	DELETE @t6db..UA_holdauth_Ex WHERE cuser_id in ('OPER-SA-0001','MANAGER-SA01')

end
GO
--修补自定项表

update a  set a.citemname =b.citemname,
		a.ilength =case when b.ilength>a.imaxlen then a.imaxlen else b.ilength end
		from @u8db..UserDef a inner join @t6db..UserDef b on a.cid =b.cid 
go
