select distinct sc.lob_id, sc.sub_category_id, p.bgtCatId, p.prodId from tbl_IMPORT_ConAgraQuotas sc inner join tbl_PRD_Products p on p.product = sc.sub_category_id and p.ownerId = sc.ownerId and p.fsl_tablecode = sc.ownerType where sc.eai_batchId = and sc.ownerId = and sc.ownerType = update tbl_IMPORT_ConAgraQuotas set fseProdId = , fseBgtCatId = where lob_id = and sub_category_id = and eai_batchId = and ownerId = and ownerType = select cm.consolidated_broker_id, ter.territoryId from tbl_IMPORT_ConAgraQuotas cm inner join tbl_TER_Territories ter on ter.internalSalesId = cm.consolidated_broker_id and ter.ownerId = cm.ownerId and ter.fsl_tablecode = cm.ownerType where cm.eai_batchId = and cm.ownerId = and cm.ownerType = update tbl_IMPORT_ConAgraQuotas set fseTerritoryId = where consolidated_broker_id = and eai_batchId = and ownerId = and ownerType = select fseTerritoryId, fseBgtCatId, fiscal_year , sum( period_#_p# ) as period_#_p# from tbl_IMPORT_ConAgraQuotas where ownerId = and ownerType = and eai_batchId = and fseTerritoryId is not null and fseBgtCatId is not null group by fseTerritoryId, fseBgtCatId, fiscal_year order by fiscal_Year update tbl_MFR_TPF_Detail set forecast_qty = , lastUpdateSource = , lastUpdate = where forecast_year = and forecast_month = and tPartnerType = 'TER' and tPartnerId = and bgtCategoryId = and productLevel = 'UOM' and productItemCode = and mfr_id = and forecast_status = 'Q' insert into tbl_MFR_TPF_Detail ( forecast_qty, lastUpdateSource, lastUpdate, forecast_year, forecast_month, tPartnerType, tPartnerId, bgtCategoryId, productLevel, productItemCode, mfr_id, forecast_status ) values ( , , , , , 'TER', , , 'UOM', , , 'Q' ) select distinct fiscal_year from tbl_IMPORT_ConAgraQuotas where eai_batchId = and fseBgtCatId is not null and fseTerritoryId is not null order by fiscal_year desc select distinct fseTerritoryId, fiscal_year from tbl_IMPORT_ConAgraQuotas where eai_batchId = and fseBgtCatId is not null and fseTerritoryId is not null