-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCompressHierarchy.sql
More file actions
25 lines (22 loc) · 1 KB
/
CompressHierarchy.sql
File metadata and controls
25 lines (22 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
--------------------------------------------------------------------------------------------------------------------------------
-- COMPRESS HIERARCHY
--------------------------------------------------------------------------------------------------------------------------------
-- Remove gaps within nested set model created when non-leaf nodes are deleted
--------------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [Utilities].[CompressTopics]
AS
SET NOCOUNT ON;
--------------------------------------------------------------------------------------------------------------------------------
-- MIND THE GAP!
--------------------------------------------------------------------------------------------------------------------------------
UPDATE Topics
SET RangeLeft = (
SELECT COUNT(*)
FROM LeftRightRange
WHERE seq <= RangeLeft
),
RangeRight = (
SELECT COUNT(*)
FROM LeftRightRange
WHERE seq <= ISNULL(RangeRight, 0)
);