|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册账号
×
下面为修改正确的代码,本人测试的数据为4位流水号,如果自己系统为3为或者5位流水号。自行把下面代码中的4替换成3或者5.
----删除原错误流水号
DELETE FROM VoucherHistory
Where CardNumber='inventory' and cContent='存货分类编码'
----求存货档案最大流水号
select max(cast(substring(iy.cinvcode,len(a.cinvccode)+1,4) as int)),a.cinvccode from inventory iy
right join
(SELECT cinvccode FROM inventoryclass where binvcend=1) a
on a.cinvccode=iy.cinvccode and left(iy.cinvcode,len(iy.cinvccode))=a.cinvccode where a.cinvccode='0705'
and len(a.cinvccode)+4=len(iy.cinvcode)
group by a.cinvccode
----插入正确的流水号
insert into VoucherHistory(cardnumber,irdflagseed,ccontent,ccontentrule,cseed,cnumber,bempty)
select 'inventory',null,'存货分类编码','',a.cinvccode,max(cast(substring(iy.cinvcode,len(a.cinvccode)+1,4) as int)),0
from inventory iy
right join
(SELECT cinvccode FROM inventoryclass where binvcend=1) a
on a.cinvccode=iy.cinvccode and left(iy.cinvcode,len(iy.cinvccode))=a.cinvccode where
len(a.cinvccode)+4=len(iy.cinvcode)
group by a.cinvccode
|
|