update vs4tjobprodmat set tmtequantity=
(SELECT Top 1 tjmtuseorder FROM VS4VJobMaterial where TJStTJPDNo=TMteTJPdNo and TJmtProductCode=TMteProductCode AND TJobCancelstatus<>1 
AND TJobApprovestatus=1 AND TMteLevel=TJMtLevel AND TMteStep=TJMtTSpdStep)
GO
update vs4tjobprodmat set tmtequantity2=
(SELECT Top 1 tjmtuseorder2 FROM VS4VJobMaterial where TJStTJPDNo=TMteTJPdNo and TJmtProductCode=TMteProductCode AND TJobCancelstatus<>1 
AND TJobApprovestatus=1 AND TMteLevel=TJMtLevel AND TMteStep=TJMtTSpdStep)
GO
update vs4tjobprodmat set tmtequantity3=
(SELECT Top 1 tjmtuseorder3 FROM VS4VJobMaterial where TJStTJPDNo=TMteTJPdNo and TJmtProductCode=TMteProductCode AND TJobCancelstatus<>1 
AND TJobApprovestatus=1 AND TMteLevel=TJMtLevel AND TMteStep=TJMtTSpdStep)
GO
update vs4tjobprodmat set tmtetotaldif=tmtequantity-TMtetotalused
GO
update vs4tjobprodmat set tmtetotaldif2=tmtequantity2-TMtetotalused2
GO
update vs4tjobprodmat set tmtetotaldif3=tmtequantity3-TMtetotalused3
GO