sql 解决方法 - Integraçãodedados de referencia - GAMA

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 解决方法 - Integraçãodedados de referencia - GAMA相关的知识,希望对你有一定的参考价值。

/* Status of items */
select IntegrationStatus, RetailStoreId, count(*)
from stra.itemreTailStore
where IntegrationStatus = 'A'
group by IntegrationStatus, RetailStoreId

/* Get last IntegrationId */

declare @lastIntegrationId as int
select top 1 @lastIntegrationId = IntegrationId from stra.ItemRetailStore order by IntegrationId desc

print 'Ultimo IntegrationId ' + cast(@lastIntegrationId as varchar)

/* Update to D, items duplicated */

update stra.ItemRetailStore
set IntegrationStatus = 'D'
where IntegrationId in (
Select IntegrationId from (
select IntegrationId,
RANK() OVER (PARTITION BY ItemId,RetailStoreId ORDER BY IntegrationId Desc) As Rank
from stra.ItemRetailStore where IntegrationStatus = 'A' /*and RetailStoreId = 'S2349'*/) As r
where r.Rank <> 1) and IntegrationId <= @lastIntegrationId

/* Insert items that does not exists */ 

insert into ra.ItemRetailStore 
(RetailStoreId,
ItemId,
SellPrice,
SellPriceNextDay,
DiscountFlag,
Status,
PresentationStock,
ProvisioningType,
PlanogramWide,
PlanogramHigh,
PlanogramDeep)
select RetailStoreId,
ItemId,
SellPrice,
SellPriceNextDay,
DiscountFlag,
Status,
PresentationStock,
ProvisioningType,
PlanogramWide,
PlanogramHigh,
PlanogramDeep
from stra.ItemRetailStore i0 
where i0.IntegrationStatus = 'A' and /*RetailStoreId = 'S2349' and */
not exists (select 1 from ra.ItemRetailStore i1 where i1.ItemId = i0.ItemId and i1.RetailStoreId = i0.RetailStoreId) and 
exists (select 1 from ra.Item i2 where i2.ItemId = i0.ItemId ) 
and IntegrationId <= @lastIntegrationId

/* Update item that already exists */

update irs
set irs.SellPrice = st_irs.SellPrice, irs.OldSellPrice = irs.SellPrice, irs.LastPriceChange = GETDATE(), irs.Status = st_irs.Status
from ra.ItemRetailStore as irs
inner join stra.ItemRetailStore st_irs on st_irs.ItemId = irs.ItemId and st_irs.RetailStoreId = irs.RetailStoreId
where st_irs.IntegrationStatus = 'A' and /*st_irs.RetailStoreId = 'S2349' and*/
exists (select 1 from ra.Item i2 where i2.ItemId = irs.ItemId )
and IntegrationId <= @lastIntegrationId

/* Mark items to processed */

update irs
set irs.IntegrationStatus = 'P'
from stra.ItemRetailStore as irs
where irs.IntegrationStatus = 'A' and /*RetailStoreId = 'S2349' and*/
exists (select 1 from ra.ItemRetailStore i1 where i1.ItemId = irs.ItemId and i1.RetailStoreId = irs.RetailStoreId) and 
exists (select 1 from ra.Item i2 where i2.ItemId = irs.ItemId )
and IntegrationId <= @lastIntegrationId

/* Status of items */

select IntegrationStatus, RetailStoreId, count(*)
from stra.itemreTailStore
where IntegrationStatus = 'A' and IntegrationId <= @lastIntegrationId
group by IntegrationStatus, RetailStoreId

以上是关于sql 解决方法 - Integraçãodedados de referencia - GAMA的主要内容,如果未能解决你的问题,请参考以下文章

sql Canção - Forçaratualizarpreçosgamacom base alterados

sql 24_7SaaS_ReprocessarRemarcaçãoAuditPreço

sql Canção - Coletahorárioschegadaficheiros +geraçãotarefas

sql VeritabanıobjelerinindeğişikliktarihçesinitutmakiçinDDLoluşturmak

sql NroTimeoutsServiçoCCSD

sql 配置alertasreceções