USE [site_fuchs] GO /****** Object: StoredProcedure [dbo].[ocms_cleanups] Script Date: 02.12.2020 21:05:05 ******/ DROP PROCEDURE [dbo].[ocms_cleanups] GO /****** Object: StoredProcedure [dbo].[ocms_cleanups] Script Date: 02.12.2020 21:05:06 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_cleanups] AS BEGIN SET NOCOUNT ON; /* UPDATE Template Property Numbering */ with tpo as ( select * , ROW_NUMBER() OVER (PARTITION BY ocms_tid ORDER BY [order], ocms_tpid) as 'tpo' from [dbo].[ocms_template_properties] ) update tp SET tp.[order] = tpo.[tpo] From [dbo].[ocms_template_properties] as tp JOIN tpo ON tp.[ocms_tpid] = tpo.[ocms_tpid]; /* UPDATE ITEM NUMBERING */ with ino as ( select * , ROW_NUMBER() OVER (PARTITION BY [parent_iid] ORDER BY [order], [ocms_iid]) as 'itmo' -- 999 for any new from [dbo].[ocms_items] ) update i SET i.[order] = ino.[itmo] From [dbo].[ocms_items] as i JOIN ino ON i.[ocms_iid] = ino.[ocms_iid] WHERE i.[order] >= 0 and i.[parent_iid] is not null END GO ALTER AUTHORIZATION ON [dbo].[ocms_cleanups] TO SCHEMA OWNER GO