delete tpf from tbl_MFR_TPF_Detail#_tpfSuffix# tpf where not exists ( select * from tbl_PRD_SKus s where s.skuId = tpf.skuId and s.ownerId = tpf.mfr_id and s.fsl_tablecode = 'MFR' ) and tpf.mfr_id = and tpf.skuId > 0 select tpf.productItemCode, s.skuId, s.sku, tpf.productLevel, tpf.forecast_year, tpf.forecast_month, tpf.forecast_status, tpf.tpartnerId, tpf.tpartnerType from tbl_MFR_TPF_Detail#_tpfSuffix# tpf inner join tbl_PRD_Skus s on s.skuId = tpf.skuId and s.ownerId = tpf.mfr_id and s.fsl_tablecode = 'MFR' where tpf.mfr_id = and tpf.productLevel = 'SKU' and tpf.forecast_status not in ( 'R', 'C', 'T', 'D' ) and tpf.productItemCode <> s.sku update tbl_MFR_TPF_Detail set productItemCode = where mfr_id = and forecast_year = and forecast_month = and forecast_status = and productItemCode = and productLevel = and tpartnerId = and tpartnerType = and skuId = select skuId from tbl_MFR_TPF_Detail where mfr_id = and forecast_year = and forecast_month = and forecast_status = and productLevel = and tpartnerId = and tpartnerType = and productItemCode = delete tbl_MFR_TPF_Detail where mfr_id = and forecast_year = and forecast_month = and forecast_status = and productItemCode = and productLevel = and tpartnerId = and tpartnerType = and skuId = select tpf.productItemCode, s.skuId, s.sku, tpf.productLevel, tpf.forecast_year, tpf.forecast_month, tpf.forecast_status, tpf.tpartnerId, tpf.tpartnerType from tbl_MFR_TPF_Detail#_tpfSuffix# tpf inner join tbl_PRD_Skus s on s.skuId = tpf.skuId and s.ownerId = tpf.mfr_id and s.fsl_tablecode = 'MFR' where tpf.mfr_id = and tpf.productLevel = 'SKU' and tpf.forecast_status not in ( 'R', 'C', 'T', 'D' ) and tpf.productItemCode <> s.sku