>>>INSERT INTO #fc >>>( >>> Symbol >>> ,Eff_Date >>>... >>> ,FCA_Backfeed_Event_iD >>>) >>> >>>SELECT >>> DJ_SYMBOL >>> ,eff_date >>>... >>> ,spi_event_id >>> FROM #staging >>> where #staging.spi_event_id not in (select fca_backfeed_event_id FROM #fc) >>>>>>
>>>INSERT INTO #fc >>>( >>> Symbol >>> ,Eff_Date >>>... >>> ,FCA_Backfeed_Event_iD >>>) >>> >>>SELECT >>> DJ_SYMBOL >>> ,eff_date >>>... >>> ,spi_event_id >>> FROM #staging >>> where #staging.DJ_symbol, #staging.eff_date not in (select symbol, eff_date FROM #fc) >>>>>>
>>> >>>;WITH cte as ( select symbol+convert(varchar,eff_date,104) as symdate from #fc ) >>>INSERT INTO #fc >>>( >>> [Symbol] >>> ,[Eff_Date] >>>... >>> ,[FCA_Backfeed_Event_iD] >>> ,[SPISourceChecksum] >>>) >>>OUTPUT inserted.symbol, inserted.eff_date, inserted.fca_backfeed_event_id INTO @NewFCTemp >>>SELECT >>> [DJ_SYMBOL] >>> ,eff_date >>>... >>> ,SPI_Event_Id >>> >>> FROM #staging stg WHERE >>> stg.dj_symbol+convert(varchar,stg.eff_date,104) not in (select symdate from cte ) >>> >>>>>>
>>WHERE NOT EXISTS (select 1 from #rfc R where R.eff_date = St.Eff_date and R.Event_ID = St.Even_ID etc.)>>
>>INSERT INTO #fc >>( >> Symbol >> ,Eff_Date >>... >> ,FCA_Backfeed_Event_iD >>) >> >>SELECT >> DJ_SYMBOL >> ,eff_date >>... >> ,spi_event_id >> FROM #staging St >> where not exists (select 1 FROM #fc fc where fc.symbol = St.symbol and fc.eff_date = St.eff_date) >>>