select invoiceDate, forecast_year, fiscalYear, forecast_month, fiscalMonth, count(*) lines, 0 newFiscalYear, 0 newFiscalMonth, 0 newForecastYear, 0 newForecastMonth from tbl_CDR_invoiceHistory with (nolock) where ownerId = and ownerType = 'MFR' group by invoiceDate, fiscalYear, fiscalMonth, forecast_year, forecast_month order by invoiceDate select * from qmd_invoiceSummary where newFiscalYear > 0 update tbl_CDR_InvoiceHistory set forecast_year = , forecast_month = , fiscalYear = , fiscalMonth = where ownerId = and ownerType = 'MFR' and forecast_year = and forecast_month = and fiscalYear = and fiscalMonth = and invoiceDate = select forecast_year, forecast_month from qmd_changes union select newForecastYear, newForecastMonth from qmd_changes order by forecast_year, forecast_month delete from tbl_MFR_TPF_Detail#_tpfSuffix# where mfr_id = and forecast_status = 'A' and tpartnerType = 'CDR' and productLevel = 'SKU' and forecast_year = and forecast_month = select fiscalYear from qmd_changes union select newFiscalYear from qmd_changes order by fiscalYear