update vs4tjobmaterial set tjmttype=(SELECT  COUNT(TPMtTPdtCode) AS C From VS4TProductMat GROUP BY TPMtTPdtCode having tpmttpdtcode=tjmtproductcode)
GO
update vs4tjobmaterial set tjmttype=0 where tjmttype is null
GO