为了解决制度流程正文文档历史版本问题,请将formtable_main_236.zdwj赋值给formtable_main_236.zdwjx,若存在formtable_main_236.zdwj有多个id的情况,则取最大值进行赋值
需求一:存在多个文档ID的,使用最大值的文档ID
验证多文档字段,并取最大ID
select id,requestid,zdmc,zdwj,instr(zdwj,',',-1),substr(zdwj,instr(zdwj,',',-1)+1 ),zdwjx from formtable_main_236 where zdwj like '%,%'
更新不含多文档的:
update formtable_main_236 set zdwjx = zdwj where zdwj not like '%,%'
更新含用多文档的,并取最大ID
update formtable_main_236 set zdwjx = substr(zdwj,instr(zdwj,',',-1)+1 ) where zdwj like '%,%'
预证
select id,requestid,zdmc,zdwj,zdwjx from uf_zdgl where id = 42829 zdwj is null not like '%,%'
需求二:如果存在多个文档版本的,要使用最新的版本。
历史版本的清单
select requestid,lcbh,zdwj,zdwjX from formtable_main_236 where zdwjx in (select id from docdetail where ishistory = 1 and id in (select zdwjx from formtable_main_236))
查存在历史版本的,最新版本是什么
select id,parentids,maindoc,doceditionid, ishistory from docdetail where ishistory = 1 and id in (select zdwjx from formtable_main_236)
用最新版本更新:文档父节点字符串parentids
update (select a.zdwjx a1,b. parentids b1 from formtable_main_236 a, docdetail b where b.ishistory = 1 and b.id = a.zdwjx and a.zdwjx in (select id from docdetail where ishistory = 1) ) set a1 = b1
用最新版本更新:主文档maindoc
update (select a.zdwjx a1,b. maindoc b1 from formtable_main_236 a, docdetail b where b.ishistory = 1 and b.id = a.zdwjx and a.zdwjx in (select id from docdetail where ishistory = 1) ) set a1 = b1