update vs4tjobproduction set tjpdtjpkcode=(select TSepDocCode from vs4tmrpstepname where tsepcode=(select TJPMTSepCode from vs4tjobproductionM where TJPMLn=1 and TJPMTJPdNo=TJPdNo)) where TJPdStatusOrder=4 and (tjpdtjpkcode='' or tjpdtjpkcode is null)
GO
update vs4tjobproduction set tjpdtjpkcode=(select top 1 tjpkcode from vs4tjobprodbook) where tjpdtjpkcode='' or tjpdtjpkcode is null
GO