1
1
-- ------------------------------------------------------------------------------------------------------------------------------
2
- -- GET TOPIC ATTRIBUTES
2
+ -- GET ATTRIBUTES
3
3
-- ------------------------------------------------------------------------------------------------------------------------------
4
4
-- Returns the most recent value of each attribute associated with a particular topic.
5
5
-- ------------------------------------------------------------------------------------------------------------------------------
6
- CREATE PROCEDURE [dbo].[GetAttributes]
6
+
7
+ CREATE
8
+ FUNCTION [dbo].[GetAttributes] (
7
9
@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
+ )
8
18
AS
9
19
10
- -- ------------------------------------------------------------------------------------------------------------------------------
11
- -- DECLARE AND SET VARIABLES
12
- -- ------------------------------------------------------------------------------------------------------------------------------
13
- SET NOCOUNT ON ;
20
+ BEGIN
14
21
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,
19
32
AttributeValue,
20
33
0 AS IsExtendedAttribute,
21
34
Version
22
- FROM AttributeIndex
23
- WHERE TopicID = @TopicID
35
+ FROM AttributeIndex
36
+ WHERE TopicID = @TopicID
24
37
25
- UNION
38
+ UNION
26
39
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 (
31
44
' @key' ,
32
- ' VARCHAR(255 )'
45
+ ' VARCHAR(128 )'
33
46
) AS AttributeKey,
34
47
Attributes .Loc .value (
35
48
' .[1]' ,
36
49
' VARCHAR(MAX)'
37
50
) AS AttributeValue,
38
51
1 AS IsExtendedAttribute,
39
52
Version
40
- FROM ExtendedAttributeIndex
41
- CROSS APPLY AttributesXml .nodes (
53
+ FROM ExtendedAttributeIndex
54
+ CROSS APPLY AttributesXml .nodes (
42
55
' /attributes/attribute'
43
56
) 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