begin tran
IF NOT EXISTS (SELECT 1 FROM IM_LOC_GRP where LOC_GRP_ID = 'IPAAS')
BEGIN
INSERT INTO [dbo].[IM_LOC_GRP]([LOC_GRP_ID],[DESCR],[DESCR_UPR],[LST_MAINT_DT],[LST_MAINT_USR_ID])
VALUES ('IPAAS','ipaas location-specific-inventory','IPAAS LOCATION-SPECIFIC-INVENTORY',getdate(),'REDROOK')
END
delete from IM_LOC_GRP_LOC where LOC_GRP_ID = 'IPAAS'
insert into IM_LOC_GRP_LOC (LOC_GRP_ID, LOC_ID, SEQ_NO, LST_MAINT_DT, LST_MAINT_USR_ID)
select 'IPAAS' as LOC_GRP_ID, LOC_ID, ROW_NUMBER() OVER (ORDER BY LOC_ID) as SEQ_NO, getdate() as LST_MAINT_DT, 'REDROOK' as LST_MAINT_USR_ID from IM_LOC
select * from IM_LOC_GRP_LOC where LOC_GRP_ID = 'IPAAS'
rollback tran
--commit tran