sql MRSSincronizaçãodegama
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql MRSSincronizaçãodegama相关的知识,希望对你有一定的参考价值。
CREATE TABLE ##ItemRetailStoreTemp (SKU bigint NOT NULL, ItemId varchar(18) NOT NULL, Store bigint NOT NULL,
RetailStoreId varchar(18) NOT NULL, [Status] char(1) NOT NULL)
-- Staples
INSERT INTO ##ItemRetailStoreTemp (SKU, ItemID, Store, RetailStoreID, [Status])
SELECT * FROM openquery(MLRMS,'
SELECT wst.sku SKU,
wst.sku ItemID,
wst.store Store,
''S''||Lpad(wst.store, 4, 0) RetailStoreID,
wst.status Status
FROM win_store wst
WHERE wst.store IN (3260)')
-- Packs
INSERT INTO ##ItemRetailStoreTemp (SKU, ItemID, Store, RetailStoreID, [Status])
SELECT * FROM openquery(MLRMS,'
SELECT pst.pack_no SKU,
pst.pack_no ItemID,
pst.store Store,
''S''||Lpad(pst.store, 4, 0) RetailStoreID,
pst.status Status
FROM packstore pst
WHERE pst.store IN (3260)')
-- Fashion Style
INSERT INTO ##ItemRetailStoreTemp (SKU, ItemID, Store, RetailStoreID, [Status])
SELECT * FROM openquery(MLRMS,'
SELECT rst.style SKU,
rst.style ItemID,
rst.store Store,
''S''||Lpad(rst.store, 4, 0) RetailStoreID,
''A'' Status
FROM rag_style_st rst
WHERE rst.store IN (3260)')
-- Fashion Sku
INSERT INTO ##ItemRetailStoreTemp (SKU, ItemID, Store, RetailStoreID, [Status])
SELECT * FROM openquery(MLRMS,'
SELECT rst.sku SKU,
rst.sku ItemID,
rst.store Store,
''S''||Lpad(rst.store, 4, 0) RetailStoreID,
rst.status Status
FROM rag_skus_st rst
WHERE rst.store IN (3260)')
-------------------------------------------------------- FINAL ---------------------------------------------------------------------------------------------------
CREATE NONCLUSTERED INDEX [Idx_1] ON ##ItemRetailStoreTemp (ItemID ASC, RetailStoreID ASC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 100) ON [PRIMARY]
CREATE TABLE ##ItemRetailStoreTemp_Piloto_Status (Store bigint NOT NULL)
DECLARE @ExisteLoja int
DECLARE @Loja int
DECLARE @UltimaLoja bigint
DECLARE @Inicio bigint
DECLARE @Fim bigint
DECLARE @Maior bigint
DECLARE @NumeroLinhas int
DECLARE @Delay datetime
DECLARE @Segundos int
SET @Segundos = 0
SET @NumeroLinhas = 1400000
SELECT @Loja = MIN(Store) FROM ##ItemRetailStoreTemp
--SELECT @Loja = (ISNULL(MAX(Store), 0) + 1) FROM ##ItemRetailStoreTemp_Piloto_Status
--SELECT @UltimaLoja = MAX(Store) FROM ##ItemRetailStoreTemp_Piloto
--SET @UltimaLoja = (@Loja + 2)
SELECT @UltimaLoja = Store FROM (SELECT TOP 1 Store FROM (SELECT TOP 20 -- Mudar para ter o NÚMERO DE LOJAS A TRATAR !!!!!!
Store FROM (SELECT DISTINCT Store FROM ##ItemRetailStoreTemp with(nolock)) tabAux ORDER BY Store) tab
ORDER BY Store DESC) aux
WHILE @Loja <= @UltimaLoja
BEGIN
SELECT @ExisteLoja = COUNT(1) FROM ra.RetailStore WHERE RetailStoreId = ('S' + RIGHT('0000' + CONVERT(nvarchar(4), @Loja), 4))
IF @ExisteLoja = 1
BEGIN
SELECT @Inicio = (MIN(SKU) - 1) FROM ##ItemRetailStoreTemp WHERE Store = @Loja
SET @Fim = (@Inicio + 1 + @NumeroLinhas)
SELECT @Maior = (MAX(SKU) + @NumeroLinhas) FROM ##ItemRetailStoreTemp WHERE Store = @Loja
WHILE @Fim <= @Maior
BEGIN
---- Atualizar existentes:
--UPDATE I SET I.[Status] = x.[Status]
--FROM ra.ItemRetailStore I INNER JOIN ##ItemRetailStoreTemp_Piloto x ON (x.ItemID = I.ItemID AND x.RetailStoreID = I.RetailStoreID)
--WHERE EXISTS (SELECT 1 FROM ra.ItemRetailStore r WHERE r.ItemID = x.ItemID AND r.RetailStoreID = x.RetailStoreID)
-- AND SKU > @Inicio AND SKU <= @Fim
--SELECT @Delay = DATEADD(SECOND, @Segundos, CONVERT(datetime, 0))
--WAITFOR DELAY @Delay
-- Inserir Novos:
INSERT INTO ra.ItemRetailStore (ItemID, RetailStoreID, [Status])
SELECT ItemID, RetailStoreID, [Status]
FROM ##ItemRetailStoreTemp x
WHERE NOT EXISTS (SELECT 1 FROM ra.ItemRetailStore r WHERE r.ItemID = x.ItemID AND r.RetailStoreID = x.RetailStoreID)
AND EXISTS (SELECT 1 FROM ra.Item r WHERE r.ItemID = x.ItemID)
AND SKU > @Inicio AND SKU <= @Fim
SELECT @Delay = DATEADD(SECOND, @Segundos, CONVERT(datetime, 0))
WAITFOR DELAY @Delay
DELETE ##ItemRetailStoreTemp WHERE Store = @Loja AND SKU > @Inicio AND SKU <= @Fim
AND ItemID IN (SELECT ItemID FROM ra.Item)
SET @Inicio = @Fim
SET @Fim = @Fim + @NumeroLinhas
END
INSERT INTO ##ItemRetailStoreTemp_Piloto_Status VALUES (@Loja)
END
SELECT @Loja = ISNULL(MIN(Store), @UltimaLoja + 1) FROM ##ItemRetailStoreTemp where Store > @Loja
--SET @Loja = @Loja + 1
END
--SELECT DISTINCT Store FROM ##ItemRetailStoreTemp_Piloto with(nolock) ORDER BY Store
--SELECT COUNT(1) FROM ##ItemRetailStoreTemp_Piloto with(nolock) --1 316 059
以上是关于sql MRSSincronizaçãodegama的主要内容,如果未能解决你的问题,请参考以下文章
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