
-- 更新单据数据(采购入库单) 功能：收付款协议升级脚本


if 	exists(select 1 from @t6db..syscolumns where id =( select id from @t6db..sysobjects where name ='rdrecord' and xtype ='u')
	and name ='cAccountPDate' )
begin
	if exists (select 1 from @u8db..sysobjects where name ='rdrecord01' and xtype ='u')

	exec('update a set bcredit=0,cvenpuomprotocol = ''999'',dCreditStart = a.ddate,iCreditPeriod = 0,dGatheringDate=b.cAccountPDate     

	   from @u8db..rdrecord01 a inner join @t6db..rdrecord b on a.id = b.id    

	   where isnull(b.cAccountPDate,'''') <>'''' and b.cvouchtype=''01''')    
	else
	begin
	if exists(select 1 from @u8db..syscolumns where id =( select id from @u8db..sysobjects where name ='rdrecord' and xtype ='u')
		and name ='dGatheringDate' )
	exec('update a set bcredit=0,cvenpuomprotocol = ''999'',dCreditStart = a.ddate,iCreditPeriod = 0,dGatheringDate=b.cAccountPDate     

	   from @u8db..rdrecord a inner join @t6db..rdrecord b on a.id = b.id    

	   where isnull(b.cAccountPDate,'''') <>'''' and b.cvouchtype=''01''')    
	end
end
go

