USE "Tfs_Configuration";
SELECT
ISNULL(d.[ KEY],a.[ KEY]) AS FeatureKey
, CASE
WHEN a.AvailabilityState=1
THEN N'Enabled'
WHEN a.AvailabilityState=0
THEN N'Disabled'
WHEN a.AvailabilityState IS NULL
THEN N'Disabled'
END AS State
, o.Owner
, n.Name
, d.Description
FROM
(
SELECT
SUBSTRING(ParentPath, LEN(N'#\FeatureAvailability\Definitions\')+1, LEN(ParentPath)) AS [key]
, regvalue AS Description
FROM
tbl_registryitems
WHERE
ParentPath LIKE '#\FeatureAvailability\Definitions\%'
AND ChildItem = N'Description\'
)
AS d
JOIN
(
SELECT
SUBSTRING(ParentPath, LEN(N'#\FeatureAvailability\Definitions\')+1, LEN(ParentPath)) AS [key]
, regvalue AS Name
FROM
tbl_registryitems
WHERE
ParentPath LIKE N'#\FeatureAvailability\Definitions\%'
AND ChildItem = N'Name\'
)
AS n
ON
n.[ KEY] = d.[ KEY]
JOIN
(
SELECT
SUBSTRING(ParentPath, LEN(N'#\FeatureAvailability\Definitions\')+1, LEN(ParentPath)) AS [key]
, regvalue AS Owner
FROM
tbl_registryitems
WHERE
ParentPath LIKE N'#\FeatureAvailability\Definitions\%'
AND ChildItem = N'Owner\'
)
AS o
ON
o.[ KEY] = d.[ KEY]
FULL OUTER JOIN
(
SELECT
SUBSTRING(ParentPath, LEN(N'#\FeatureAvailability\Entries\')+1, LEN(ParentPath)) AS [key]
, isnull(regvalue, 0) AS AvailabilityState
FROM
tbl_registryitems
WHERE
ParentPath LIKE N'#\FeatureAvailability\Entries\%'
AND ChildItem = N'AvailabilityState\'
)
AS a
ON
a.[KEY] = d.[KEY]
ORDER BY
3
, 4
, 5