原系统 :MSSQL SERVER 7.0+DELPHI 新系统 :MSSQL SERVER 2000 + DELPHI 需要处理资料:spkfk(商品库房库) : (spid , //商品内码 pk spbh ,//商品编号 Unique index spmch ,//商品名称 shpgg ,//商品规格 dw , //单位 shpchd //商品产地 ) 新系统中资料来源为原系统中 SPKFK , 原系统中无 SPID 字段 , 需在导入时生成。 将旧系统业务数据库(dtx4) 附加到MSSQL2000中 执行如下操作: use st70 --新系统业务数据库
declare @tran_point int set @tran_point=@@trancount --获取系统事务数 if @tran_point=0 begin tran tran_c --开始事务 else save tran tran_c --设置事务保存点 declare @spid char(11) --定义变量 set @spid='' declare @id int --定义 内码 数值变量 set @id = 0 --初始化 起始 值 select @spid as spid , spbh ,spmch ,shpgg , dw ,shpchd into #t1 --提取原系统中 商品信息 from dtx40..spkfk if @@error<>0 goto err_lab update #t1 set spid=@id ,@id=@id+1 -- 生成商品内码数值 if @@error<>0 goto err_lab
update #t1 set spid='SPH' + REPLICATE('0',8-len(ltrim(rtrim(spid))))+ltrim(rtrim(spid)) --生成商品内码(商品内码为:SPHxxxxxxxxx) if @@error<>0 goto err_lab
delete from spkfk --清空 目的表 if @@error<>0 goto err_lab insert into spkfk(spid , spbh , spmch ,shpgg ,dw ,shpchd) --将数据插入到目的表 select spid , spbh , spmch ,shpgg ,dw ,shpchd from #t1 if @@error<>0 goto err_lab drop table #t1 if @tran_point=0 goto returnlb
err_lab: rollback tran tran_c --取消事务 returnlb: commit tran tran_c --提交事务 以上为商品资料的内码处理,其他资料同上。 
|