11

我已经搜索并尝试了几个小时来获取一个查询,该查询为我提供了来自 SSRS 服务的所有当前订阅以及参数及其值,以便可以在新服务器上重新创建它们(修剪后)。

例如,一个简单的报告可能是 HoursByDepartment,它采用三个参数:

@From =Today - 7 days (Default)
@To   = Today (Default)
@Dept = 2 (part of subscription)

我想得到的是这些方面的东西(或者可以让我创建报告的东西)

Report            ParamName   ParamValue    Default
HoursByDepartment From        Today-7days    True
HoursByDepartment To          Today          True
HoursByDepartment Dept        2              False

或者

Report             Param1Name   Param1Value   Param1Def   Param2Name   Param2Value    Param2Def     
HoursByDepartment  From         Today-7days   True        To           Today          True

我对 XSl 非常满意,所以如果我能得到类似的东西,我可以使用它:

<subid>
    <report>
        <ParameterValues>
            <ParameterValue>
                <Name>MinAvailable</Name>
                <Value>10000</Value>
            </ParameterValue>
            <ParameterValue>
                <Name>OwnerIDs</Name>
                <Value>0</Value>
            </ParameterValue>
            <ParameterValue>
                <Name>ShowCosts</Name>
                <Value>False</Value>
            </ParameterValue>
            <ParameterValue>
                <Name>MinValue</Name>
                <Value>0</Value>
            </ParameterValue>
        </ParameterValues>
    </report>
</subid>
4

3 回答 3

10

这个脚本应该让你有一个好的开始。此查询将为每个报表订阅的每个参数返回一行,或者为不使用参数的订阅仅返回一行。如果您的偏好是转换它,您可能需要重新编写脚本以将其转换为 xml 格式。

这来自列出订阅的 SSRS 报告,包括参数及其值(不确定我更改了多少原始文件,如果有的话。)

WITH
[Sub_Parameters] AS
(
SELECT 
[SubscriptionID],
[Parameters] = CONVERT(XML,a.[Parameters])
FROM [Subscriptions] a
),
[MySubscriptions] AS
(
SELECT DISTINCT
[SubscriptionID],
[ParameterName] = QUOTENAME(p.value('(Name)[1]', 'nvarchar(max)')),
[ParameterValue] = p.value('(Value)[1]', 'nvarchar(max)')
FROM 
[Sub_Parameters] a
CROSS APPLY [Parameters].nodes('/ParameterValues/ParameterValue') t(p)
),
[SubscriptionsAnalysis] AS
(
SELECT
a.[SubscriptionID],
a.[ParameterName],
[ParameterValue] = 
(SELECT
STUFF(( 
SELECT [ParameterValue] + ', ' as [text()]
FROM [MySubscriptions]
WHERE 
[SubscriptionID] = a.[SubscriptionID]
AND [ParameterName] = a.[ParameterName]
FOR XML PATH('')
),1, 0, '')
+'')
FROM [MySubscriptions] a
GROUP BY a.[SubscriptionID],a.[ParameterName]
)
SELECT
a.[SubscriptionID],
c.[UserName] AS Owner, 
b.Name,
b.Path,
a.[Locale], 
a.[InactiveFlags], 
d.[UserName] AS Modified_by, 
a.[ModifiedDate], 
a.[Description], 
a.[LastStatus], 
a.[EventType], 
a.[LastRunTime], 
a.[DeliveryExtension],
a.[Version],
e.[ParameterName],
LEFT(e.[ParameterValue],LEN(e.[ParameterValue])-1) as [ParameterValue],
SUBSTRING(b.PATH,2,LEN(b.PATH)-(CHARINDEX('/',REVERSE(b.PATH))+1)) AS ProjectName
FROM 
[Subscriptions] a 
INNER JOIN [Catalog] AS b
ON a.[Report_OID] = b.[ItemID]
LEFT OUTER JOIN [Users] AS c
ON a.[OwnerID] = c.[UserID]
LEFT OUTER JOIN [Users] AS d
ON a.MODIFIEDBYID = d.Userid
LEFT OUTER JOIN [SubscriptionsAnalysis] AS e 
ON a.SubscriptionID = e.SubscriptionID;

但是,如果这是从 2005 到 2008 的升级,您可能需要考虑使用此工具。如果您要从此服务器中删除 SSRS 并移动到使用相同版本的不同服务器,则最好按照Microsoft 此处的说明移动整个 reportserver 和 reportservertempdb 数据库。

于 2012-09-13T15:12:19.673 回答
3

下面是更新后的@dev_etter 查询的一个版本以返回扩展设置。

WITH
[Sub_Parameters] AS
    (SELECT 
        [SubscriptionID],
        [Parameters] = CONVERT(XML,a.[Parameters]),
        [ExtensionSettings] = CONVERT(XML,a.[ExtensionSettings])
     FROM [Subscriptions] a
    )

, [MySubscriptions] AS (
    SELECT --DISTINCT 
        [SubscriptionID],
        [ParameterName] = QUOTENAME(p.value('(Name)[1]', 'nvarchar(max)')),
        [ParameterValue] = p.value('(Value)[1]', 'nvarchar(max)')
    FROM [Sub_Parameters] a
    CROSS APPLY [Parameters].nodes('/ParameterValues/ParameterValue') t(p)
    UNION
    SELECT --DISTINCT 
        [SubscriptionID],
        [ExtensionSettingName] = QUOTENAME(e.value('(Name)[1]', 'nvarchar(max)')),
        [ExtensionSettingValue] = e.value('(Value)[1]', 'nvarchar(max)')
    FROM [Sub_Parameters] a
    CROSS APPLY [ExtensionSettings].nodes('/ParameterValues/ParameterValue') t(e)
    )

, [SubscriptionsAnalysis] AS (
    SELECT
        a.[SubscriptionID],
        a.[ParameterName],
        [ParameterValue] =
              (SELECT STUFF((SELECT [ParameterValue] + ', ' as [text()] 
               FROM [MySubscriptions] 
               WHERE [SubscriptionID] = a.[SubscriptionID] 
                   AND [ParameterName] = a.[ParameterName] FOR XML PATH('')),1, 0, '')+'')
    FROM [MySubscriptions] a
    GROUP BY a.[SubscriptionID],a.[ParameterName]
    )

SELECT
    a.[SubscriptionID],
    c.[UserName] AS [Owner], 
    b.[Name],
    b.[Path],
    a.[Locale], 
    a.[InactiveFlags], 
    d.[UserName] AS [Modified_by], 
    a.[ModifiedDate], 
    a.[Description], 
    a.[LastStatus], 
    a.[EventType], 
    a.[LastRunTime], 
    a.[DeliveryExtension],
    a.[Version],
    e.[ParameterName],
    LEFT(e.[ParameterValue],LEN(e.[ParameterValue])-1) as [ParameterValue],
    SUBSTRING(b.[PATH],2,LEN(b.[PATH])-(CHARINDEX('/',REVERSE(b.[PATH]))+1)) AS [ProjectName]
FROM [Subscriptions] a 
INNER JOIN [Catalog] AS b ON a.[Report_OID] = b.[ItemID]
LEFT OUTER JOIN [Users] AS c ON a.[OwnerID] = c.[UserID]
LEFT OUTER JOIN [Users] AS d ON a.[ModifiedByID] = d.[Userid]
LEFT OUTER JOIN [SubscriptionsAnalysis] AS e ON a.[SubscriptionID] = e.[SubscriptionID]
;
于 2018-08-21T14:29:17.067 回答
1

这对于评估给定报告的订阅中特定参数的使用非常有帮助,尤其是当参数变为必需时,查看哪些订阅需要更新。我采用了@Chumz 的查询,因为它比@dev_etter 的更易读,并对其进行了修改以显示数据驱动订阅的参数,其中参数 XML 中<Value>只有 a :<Field>

WITH
[Sub_Parameters] AS
    (SELECT 
        [SubscriptionID],
        [Parameters] = CONVERT(XML,[Parameters]),
        [ExtensionSettings] = CONVERT(XML,[ExtensionSettings])
     FROM [Subscriptions]
    )

, [MySubscriptions] AS (
    SELECT --DISTINCT 
        [SubscriptionID],
        [ParameterName] = QUOTENAME(p.value('(Name)[1]', 'nvarchar(max)')),
        [ParameterValue] = ISNULL(p.value('(Value)[1]', 'nvarchar(max)'),p.value('(Field)[1]', 'nvarchar(max)')),
        [ParameterType] = CASE WHEN p.value('(Field)[1]', 'nvarchar(max)') IS NOT NULL THEN 'Query' ELSE 'Static' END
    FROM [Sub_Parameters] sp
    CROSS APPLY [Parameters].nodes('/ParameterValues/ParameterValue') t(p)
    UNION
    SELECT --DISTINCT 
        [SubscriptionID],
        [ExtensionSettingName] = QUOTENAME(e.value('(Name)[1]', 'nvarchar(max)')),
        [ExtensionSettingValue] = ISNULL(e.value('(Value)[1]', 'nvarchar(max)'),e.value('(Field)[1]', 'nvarchar(max)')),
        [ExtensionSettingType] = CASE WHEN e.value('(Field)[1]', 'nvarchar(max)') IS NOT NULL THEN 'Query' ELSE 'Static' END
    FROM [Sub_Parameters] sp
    CROSS APPLY [ExtensionSettings].nodes('/ParameterValues/ParameterValue') t(e)
    )

, [SubscriptionsAnalysis] AS (
    SELECT
        ms.[SubscriptionID],
        ms.[ParameterName],
        ms.[ParameterType],
        [ParameterValue] =
              (SELECT STUFF((SELECT [ParameterValue] + ', ' as [text()] 
               FROM [MySubscriptions] 
               WHERE [SubscriptionID] = ms.[SubscriptionID] 
                   AND [ParameterName] = ms.[ParameterName] FOR XML PATH('')),1, 0, '')+'')
    FROM [MySubscriptions] ms
    GROUP BY ms.[SubscriptionID],ms.[ParameterName],ms.[ParameterType]
    )

SELECT
    s.[SubscriptionID],
    o.[UserName] AS [Owner], 
    c.[Name],
    c.[Path],
    s.[Locale], 
    s.[InactiveFlags], 
    m.[UserName] AS [Modified_by], 
    s.[ModifiedDate], 
    s.[Description], 
    s.[LastStatus], 
    CASE WHEN DATALENGTH(s.[DataSettings]) IS NULL THEN 'False' ELSE 'True' END AS [IsDataDriven],
    s.[EventType], 
    s.[LastRunTime], 
    CASE s.[DeliveryExtension] WHEN 'Report Server Email' THEN 'Email' WHEN 'Report Server FileShare' THEN 'File Drop' ELSE s.[DeliveryExtension] END AS SubscriptionType,
    sa.[ParameterName],
    sa.[ParameterType],
    LEFT(sa.[ParameterValue],LEN(sa.[ParameterValue])-1) as [ParameterValue]
FROM [Subscriptions] s
INNER JOIN [Catalog] AS c ON s.[Report_OID] = c.[ItemID]
LEFT OUTER JOIN [Users] AS o ON s.[OwnerID] = o.[UserID]
LEFT OUTER JOIN [Users] AS m ON s.[ModifiedByID] = m.[Userid]
LEFT OUTER JOIN [SubscriptionsAnalysis] AS sa ON s.[SubscriptionID] = sa.[SubscriptionID];
于 2020-01-27T13:20:41.590 回答