begin
update a set a.sglzbbh = b.sname+'-'+convert(char(200),(1+isnull(SUBSTRING(c.glh,CHARINDEX('-', c.glh)+1, LEN(c.glh)),0)))
from workplan a join org_employee b on b.id = a.idowner
join (select aa.idowner id,max(SUBSTRING(aa.sglzbbh, CHARINDEX('-', aa.sglzbbh)+1, LEN(aa.sglzbbh))) glh
from workplan aa group by aa.idowner ) c on c.id = a.idowner
where a.id = '${targetID}'
--自动关联上周计划编号
--自动关联上周计划编号
update a set a.idszzb = b.id
from workplan a join workplan b
on left(a.sglzbbh,charindex('-',a.sglzbbh)-1)+'-'+convert(char(200),isnull(SUBSTRING(a.sglzbbh,CHARINDEX('-', a.sglzbbh)+1, LEN(a.sglzbbh)),0)-1) = b.sglzbbh
where a.id = '${targetID}'
--自动上计划关联下周计划编号
update b set b.idxzjh = a.id
from workplan a join workplan b
on left(a.sglzbbh,charindex('-',a.sglzbbh)-1)+'-'+convert(char(200),isnull(SUBSTRING(a.sglzbbh,CHARINDEX('-', a.sglzbbh)+1, LEN(a.sglzbbh)),0)-1) = b.sglzbbh
where a.id = '${targetID}'
end