Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Данные

Запрос

PRESENTATION_STOCK_HISTORY

Code Block
languagesql
update hseth
set end_date=cast(getdate() as date)
from PRESENTATION_STOCK_HISTORY h
where ( (isnull(PRESENTATION_1, -1) != isnull((select PRESENTATION_1 from RPM_PRESENTATION s where s.sku_id=h.sku_id and s.store_id=h.store_id), -1))
or (not exists (select 1 from RPM_PRESENTATION s where s.sku_id=h.sku_id and s.store_id=h.store_id)) )
      and end_date is null;

Code Block
languagesql
update hset end_date=cast(getdate() as date)
from insert into PRESENTATION_STOCK_HISTORY h
where ( (isnull(PRESENTATION_1, -1) != isnull((select sku_id, store_id, PRESENTATION_1, from RPM_PRESENTATION s where s.start_date)
select sku_id=h.sku_id and s., store_id=h.store_id), -1))
or (, PRESENTATION_1, cast(getdate() as date)
from RPM_PRESENTATION s
where not exists (select 1 from RPMPRESENTATION_STOCK_PRESENTATIONHISTORY sh where sh.sku_id=hs.sku_id and sh.store_id=hs.store_id)) )
      and h.end_date is null);

SALES_SKU и SALES_GROUP 

Заполняется вызовом процедуры after_SALES_SKU_DAY (@sdate)

WH_VOLUME и WH_VALUE в SALES_SKU_DAY

Заполняется вызовом процедуры after_SALES_SKU_DAY (@sdate)

SKU_RANGE 

Code Block
languagesql
update sku_range
set end_date=getdate(), updated=getdate()
where end_date is null 
  and not exists (select 1 from sku_range_current c where sku_range.sku_id=c.sku_id and sku_range.store_id=c.store_id)
  and exists (select 1 from sku_range_current);

Code Block
languagesql
insert into sku_range (sku_id, store_id, start_date, updated)
select sku_id, store_id, getdate(), getdate()
from sku_range_current c
where not exists (select 1 from sku_range r where r.sku_id=c.sku_id and r.store_id=c.store_id and r.end_date is null);