-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGetExtendedAttribute.sql
37 lines (31 loc) · 1.73 KB
/
GetExtendedAttribute.sql
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
26
27
28
29
30
31
32
33
34
35
36
37
--------------------------------------------------------------------------------------------------------------------------------
-- GET EXTENDED ATTRIBUTE
--------------------------------------------------------------------------------------------------------------------------------
-- Given a TopicID and an AttributeKey, retrieves the value of the attribute from the index.
--------------------------------------------------------------------------------------------------------------------------------
CREATE
FUNCTION [dbo].[GetExtendedAttribute]
(
@TopicID INT,
@AttributeKey NVARCHAR(255)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
------------------------------------------------------------------------------------------------------------------------------
-- DECLARE AND DEFINE VARIABLES
------------------------------------------------------------------------------------------------------------------------------
DECLARE @AttributeValue NVARCHAR(MAX) = NULL
------------------------------------------------------------------------------------------------------------------------------
-- RETRIEVE VALUE
------------------------------------------------------------------------------------------------------------------------------
SELECT @AttributeValue = AttributesXml
.query('/attributes/attribute[@key=sql:variable("@AttributeKey")]')
.value('.', 'NVARCHAR(MAX)')
FROM ExtendedAttributeIndex
WHERE TopicID = @TopicID
------------------------------------------------------------------------------------------------------------------------------
-- RETURN VALUE
------------------------------------------------------------------------------------------------------------------------------
RETURN @AttributeValue
END