on x.DATADATE COLLATE Chinese_Taiwan_Stroke_CS_AI = y.DATADATEand x.EQPID COLLATE Chinese_Taiwan_Stroke_CS_AI = y.EQPID where x.DATADATE = convert(varchar(10),getdate()-1,120) order by 1,2 ----OEE By Entity----delete from dbo.OEE_BY_ENTITY_W where DATADATE = convert(varchar(10),getdate()-1,120)insert into OEE_BY_ENTITY_Wselect x.DATADATE ,x.ENTITY ,x.UT ,x.UP ,x.SD ,x.UD ,x.STDCT ,x.M_CT ,x.QTY ,x.REWORK ,ISNULL(y.WAFER_CNT,0) SCRAP ,x.U ,x.E ,case when QTY > 0 then (1-(REWORK+ISNULL(y.WAFER_CNT,0))/QTY)else 1 end P ,case when QTY > 0 then x.U*x.E*(1-(REWORK+ISNULL(y.WAFER_CNT,0))/QTY)else x.U*x.E*1 end OEE from (select tbl1.DATADATE ,tbl1.ENTITY ,tbl1.UT ,tbl1.UP ,tbl1.SD ,tbl1.UD ,tbl3.STDCT ,tbl2.M_CT ,tbl4.QTY ,tbl4.REWORK