11-- ------------------------------------------------------------------------------------------------------------------------------
2- -- GET TOPIC ATTRIBUTES
2+ -- GET ATTRIBUTES
33-- ------------------------------------------------------------------------------------------------------------------------------
44-- Returns the most recent value of each attribute associated with a particular topic.
55-- ------------------------------------------------------------------------------------------------------------------------------
6- CREATE PROCEDURE [dbo].[GetAttributes]
6+
7+ CREATE
8+ FUNCTION [dbo].[GetAttributes] (
79 @TopicID INT = - 1
10+ )
11+ RETURNS @Attributes TABLE
12+ (
13+ AttributeKey NVARCHAR (255 ) NOT NULL ,
14+ AttributeValue NVARCHAR (MAX ) NOT NULL ,
15+ IsExtendedAttribute BIT ,
16+ Version DATETIME
17+ )
818AS
919
10- -- ------------------------------------------------------------------------------------------------------------------------------
11- -- DECLARE AND SET VARIABLES
12- -- ------------------------------------------------------------------------------------------------------------------------------
13- SET NOCOUNT ON ;
20+ BEGIN
1421
15- -- ------------------------------------------------------------------------------------------------------------------------------
16- -- SELECT MOST RECENT ATTRIBUTES
17- -- ------------------------------------------------------------------------------------------------------------------------------
18- SELECT AttributeKey,
22+ -- ------------------------------------------------------------------------------------------------------------------------------
23+ -- SETUP INSERT
24+ -- ------------------------------------------------------------------------------------------------------------------------------
25+ INSERT
26+ INTO @Attributes
27+
28+ -- ------------------------------------------------------------------------------------------------------------------------------
29+ -- SELECT MOST RECENT ATTRIBUTES
30+ -- ------------------------------------------------------------------------------------------------------------------------------
31+ SELECT AttributeKey,
1932 AttributeValue,
2033 0 AS IsExtendedAttribute,
2134 Version
22- FROM AttributeIndex
23- WHERE TopicID = @TopicID
35+ FROM AttributeIndex
36+ WHERE TopicID = @TopicID
2437
25- UNION
38+ UNION
2639
27- -- ------------------------------------------------------------------------------------------------------------------------------
28- -- PARSE MOST RECENT EXTENDED ATTRIBUTES
29- -- ------------------------------------------------------------------------------------------------------------------------------
30- SELECT Attributes .Loc .value (
40+ -- ------------------------------------------------------------------------------------------------------------------------------
41+ -- PARSE MOST RECENT EXTENDED ATTRIBUTES
42+ -- ------------------------------------------------------------------------------------------------------------------------------
43+ SELECT Attributes .Loc .value (
3144 ' @key' ,
32- ' VARCHAR(255 )'
45+ ' VARCHAR(128 )'
3346 ) AS AttributeKey,
3447 Attributes .Loc .value (
3548 ' .[1]' ,
3649 ' VARCHAR(MAX)'
3750 ) AS AttributeValue,
3851 1 AS IsExtendedAttribute,
3952 Version
40- FROM ExtendedAttributeIndex
41- CROSS APPLY AttributesXml .nodes (
53+ FROM ExtendedAttributeIndex
54+ CROSS APPLY AttributesXml .nodes (
4255 ' /attributes/attribute'
4356 ) AS Attributes(Loc)
44- WHERE TopicID = @TopicID
45- ORDER BY AttributeKey
57+ WHERE TopicID = @TopicID
58+ ORDER BY AttributeKey
59+
60+ -- ----------------------------------------------------------------------------------------------------------------------------
61+ -- RETURN
62+ -- ----------------------------------------------------------------------------------------------------------------------------
63+ RETURN
64+
65+ END
0 commit comments