使用T-SQL查找与列关联的扩展属性

时间:2016-04-30 17:27:08

标签: sql sql-server tsql

下面的查询选择给定表中具有特定扩展属性集的列。

然后,我希望使用LEFT JOIN查找与该列关联的所有其他扩展属性,并在将来的步骤中查看PIVOT

我正在寻找一种方法将突出显示的连接限制为仅与当前列关联的属性,并突出显示下面的问题区域。

SELECT
    C.NAME AS ColumnName
    ,PropertyName = CONVERT(VARCHAR(200), EXP2.NAME)
    ,PropertyValue = CONVERT(VARCHAR(200), EXP2.value)
FROM sys.extended_properties AS EXP

LEFT JOIN sys.columns AS C ON C.object_id = EXP.major_id
    AND C.column_id = EXP.minor_id

-------------------------------------------------------
-- I'm looking for all 'additional' extended properties 
-- associated with this column, however the following 
-- join only joins back to table level
-------------------------------------------------------

LEFT JOIN sys.extended_properties AS EXP2 ON OBJECT_NAME(EXP2.major_id) = OBJECT_NAME(EXP.major_id)
    AND NOT EXP2.NAME = 'DEFINE_IMPORTABLE'
    AND EXP2.NAME LIKE 'DEFINE_%'

--- ^ Perhaps joining to another alias of sys.columns would work here?

WHERE EXP.class_desc = 'OBJECT_OR_COLUMN'
    AND EXP.NAME = 'DEFINE_IMPORTABLE'
    AND EXP.value = '1'
    AND NOT C.NAME IS NULL
    AND OBJECT_NAME(EXP.major_id) = 'MyTable'

0 个答案:

没有答案