sql Canção - Tombamento por Lista de Produtos

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql Canção - Tombamento por Lista de Produtos相关的知识,希望对你有一定的参考价值。


DECLARE @RetailStoreId VARCHAR(18) SET @RetailStoreId='S00XX'

----------------------------------------------------

-- Cria o cabeçalho das tasks
--
INSERT INTO [tm].[Task] ([AlertTypeId],[SchedConfigId],[Status],[Priority],[RetailStoreId],[ScheduledDate],[CreateUser],[CreateDate],[Description]
           ,[ActionId],[Name],[ProfileId],[ExpectedFinishDate],[FinishDate],[ChecklistId],[FinishTaskUser],[LastUpdateUser],[StoreSectionId]
           ,[StartDate],[AlertId],[DeviceId],[Shared],[ParentTaskId],[ResolutionType],[SharedCloseType],[LastUpdateDate],[ExternalCode]
           ,[Owner],[ViewPVP],[PrintLabel],[ReopenUser],[ReopenDate],[IsItemGroupOriented],[ItemGroupId],[OriginalTaskId],[AlertConfigId],[PriceChangeDate])
select 
5, null, 'A', 0 , @RetailStoreId, GETDATE(), 'admbo', GETDATE(), 'TOMBAMENTO ' + SUBSTRING(ac.Description, 23,100), 
14, 'TOMBAMENTO ' + SUBSTRING(ac.Description, 23,100), 82, '2017-08-13 08:00:00', null, null, null, null, 2, 
null, null, null, 0, null, null, null, null, null, 
null, null, null, null, null, 1, null, null, null, null
from tm.AlertConfig ac , ra.BusinessStructureItem bs
where ac.ActionId=1 and ac.BusinessStrucutureId = bs.BusinessStructureListId

--
-- Cria os produtos para cada task  - executar 1 a 1
-- 01
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Açougue' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '2.001%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 02
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Bazar' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like '3.001%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 03
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Bebidas' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.002%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 04
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Comodities' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.001%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 05
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Confeitaria' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '2.003%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 06
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Eletro' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '3.002%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 07
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO FLV' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '2.006%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 08
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Frios' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '2.005%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 09
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Higiene e Beleza' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.007%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 10
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Limpeza' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.008%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 11
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Mercearia Doce' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.003%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 12
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Mercearia Salgada' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.004%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 13
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Padaria' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '2.002%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 14
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Pas Congelados' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.005%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 15
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Pas Refrigerados' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.006%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 16
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Pet Shop' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.009%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 17
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Rotisserie' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '2.004%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 18
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Tabacaria' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.010%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 19
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Textil' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '3.003%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')

-- 20
INSERT INTO [MRS_InStore_Cancao].[tm].[TaskItem]
           ([TaskId],[AlertItemId],[Status],[Quantity],[PickingTime],[LastUpdateUser],[LastUpdateDate],[RetailStoreId],[ItemId],[ActionId],[IsAvailableForAlerts]
           ,[POSPrice],[LabelPrice],[OldERPPrice],[ERPPrice],[ShrinkageReasonId],[PriceDivergence],[ExpectedQuantity],[ExpirationDate],[BOQuantity]
,[MarkdownReason],[MarkdownItemId],[ItemBarcode],[PickCount],[CheckExpirationDate],[MinDaysToExpire],[Observation],[ReceptionUnit],[ReceptionUnitQty] ,[Forbidding],[CountDiffReasonId],[ItemGroupId],[FirstPickingTime])  select distinct (select taskid from tm.Task where Description = 'TOMBAMENTO Vida Saudavel' and Status='A' and RetailStoreId=@RetailStoreId)   , null, 'A', 0, NULL, 'admbo', GETDATE(), @RetailStoreId, ir.ItemId, 14, 1, NULL, NULL, ir.SellPrice, ir.SellPrice, 0,0,10, NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.011%' and i.ItemId not in (select distinct(igd.ItemId) from ra.ItemGroup ig inner join ra.ItemGroupDetail igd on igd.ItemGroupId = ig.ItemGroupId where RetailStoreId=@RetailStoreId and Name not like '%lâmina%')


commit;
--
-- Após conferir, se ok:  commit
-- Senão: rollback
--
-- Para ver a quantidade por tarefa
--
-----------------------------
select 'TOMBAMENTO Açougue' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like '2.001%'  union 
select 'TOMBAMENTO Bazar' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '3.001%'  union 
select 'TOMBAMENTO Bebidas' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.002%'  union 
select 'TOMBAMENTO Comodities' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.001%'  union 
select 'TOMBAMENTO Confeitaria' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '2.003%'  union 
select 'TOMBAMENTO Eletro' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '3.002%'  union 
select 'TOMBAMENTO FLV' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '2.006%'  union 
select 'TOMBAMENTO Frios' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '2.005%'  union 
select 'TOMBAMENTO Higiene e Beleza' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.007%'  union 
select 'TOMBAMENTO Limpeza' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.008%'  union 
select 'TOMBAMENTO Mercearia Doce' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.003%'  union 
select 'TOMBAMENTO Mercearia Salgada' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.004%'  union 
select 'TOMBAMENTO Padaria' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '2.002%'  union 
select 'TOMBAMENTO Pas Congelados' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.005%'  union 
select 'TOMBAMENTO Pas Refrigerados' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.006%'  union 
select 'TOMBAMENTO Pet Shop' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.009%'  union 
select 'TOMBAMENTO Rotisserie' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '2.004%'  union 
select 'TOMBAMENTO Tabacaria' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.010%'  union 
select 'TOMBAMENTO Textil' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '3.003%'  union 
select 'TOMBAMENTO Vida Saudavel' , count(distinct i.itemid) FROM RA.ItemRetailStore ir, ra.Item i, ra.ItemScanCode sc WHERE sc.ItemId = i.ItemId and sc.ScanCodeType <> 'VARW' and ir.STATUS in ('A', 'C') and RetailStoreId=@RetailStoreId and ir.ItemId = i.ItemId and i.HierarchicalStructureId like  '1.011%'   

以上是关于sql Canção - Tombamento por Lista de Produtos的主要内容,如果未能解决你的问题,请参考以下文章

sql Canção - Tempo Consulta Item MRS

sql Canção - Tombamento por Auditoria Adhoc

sql Canção - Tombamento por Lista de Produtos

sql GPA - Reprocessarintegração

sql Parasincronização物理待命

sql 24_7SaaS_ReprocessarRemarcaçãoAuditPreço