@@ -41,7 +41,7 @@ IF (@StartDate IS NULL)
4141 END
4242
4343-- ------------------------------------------------------------------------------------------------------------------------------
44- -- SELECT TOPIC ATTRIBUTES
44+ -- CREATE CONSOLIDATED TOPIC ATTRIBUTE RECORD
4545-- ------------------------------------------------------------------------------------------------------------------------------
4646;WITH TopicAttributes
4747AS (
@@ -68,7 +68,7 @@ WHERE Version > @StartDate
6868 AND Version < @EndDate
6969
7070-- ------------------------------------------------------------------------------------------------------------------------------
71- -- SELECT EXTENDED ATTRIBUTES
71+ -- CREATE CONSOLIDATED EXTENDED ATTRIBUTES RECORD
7272-- ------------------------------------------------------------------------------------------------------------------------------
7373;WITH TopicExtendedAttributes
7474AS (
@@ -86,13 +86,67 @@ SET Version = @EndDate
8686WHERE RowNumber = 1
8787
8888-- ------------------------------------------------------------------------------------------------------------------------------
89- -- DELETE CONSOLIDATED ATTRIBUTES
89+ -- DELETE CONSOLIDATED EXTENDED ATTRIBUTES
9090-- ------------------------------------------------------------------------------------------------------------------------------
9191DELETE
9292FROM ExtendedAttributes
9393WHERE Version > @StartDate
9494 AND Version < @EndDate
9595
96+ -- ------------------------------------------------------------------------------------------------------------------------------
97+ -- CREATE CONSOLIDATED RELATIONSHIPS RECORD
98+ -- ------------------------------------------------------------------------------------------------------------------------------
99+ ;WITH TopicRelationships
100+ AS (
101+ SELECT Version ,
102+ RowNumber = ROW_NUMBER () OVER (
103+ PARTITION BY Source_TopicID,
104+ RelationshipKey,
105+ Target_TopicID
106+ ORDER BY Version DESC
107+ )
108+ FROM Relationships
109+ WHERE Version > @StartDate
110+ AND Version <= @EndDate
111+ )
112+ UPDATE TopicRelationships
113+ SET Version = @EndDate
114+ WHERE RowNumber = 1
115+
116+ -- ------------------------------------------------------------------------------------------------------------------------------
117+ -- DELETE CONSOLIDATED RELATIONSHIPS
118+ -- ------------------------------------------------------------------------------------------------------------------------------
119+ DELETE
120+ FROM Relationships
121+ WHERE Version > @StartDate
122+ AND Version < @EndDate
123+
124+ -- ------------------------------------------------------------------------------------------------------------------------------
125+ -- CREATE CONSOLIDATED TOPIC REFERENCES RECORD
126+ -- ------------------------------------------------------------------------------------------------------------------------------
127+ ;WITH TopicReferenceVersions
128+ AS (
129+ SELECT Version ,
130+ RowNumber = ROW_NUMBER () OVER (
131+ PARTITION BY Source_TopicID
132+ ORDER BY Version DESC
133+ )
134+ FROM TopicReferences
135+ WHERE Version > @StartDate
136+ AND Version <= @EndDate
137+ )
138+ UPDATE TopicReferenceVersions
139+ SET Version = @EndDate
140+ WHERE RowNumber = 1
141+
142+ -- ------------------------------------------------------------------------------------------------------------------------------
143+ -- DELETE CONSOLIDATED TOPIC REFERENCES
144+ -- ------------------------------------------------------------------------------------------------------------------------------
145+ DELETE
146+ FROM TopicReferences
147+ WHERE Version > @StartDate
148+ AND Version < @EndDate
149+
96150-- ------------------------------------------------------------------------------------------------------------------------------
97151-- COMMIT TRANSACTION
98152-- ------------------------------------------------------------------------------------------------------------------------------
0 commit comments