数据源查询

时间:2016-05-23 17:22:14

标签: ssis ssas datasource jobs

美好的一天,      我需要创建一个包含有关我的SSAS作业的信息的电子表格。我需要包含的一个数据是在作业中运行的SSIS包中使用的数据源。我有一个查询,但它返回一个错误消息'传递给LEFT或SUBSTRING函数的无效长度参数。'任何人都可以帮我修复此问题或建议一种方法,让我更轻松地访问该信息吗?

USE msdb
GO

WITH XMLNAMESPACES (N'www.microsoft.com/SqlServer/Dts' AS DTS)

   SELECT JobName, PackageName, 
    pd.ConnectionManagerName,
    pd.ConnectionType,
    pd.ConnectionString     
FROM        
(SELECT
  JOB.name AS JobName, REVERSE(LEFT(STEP.ReversePackagePath, CHARINDEX('\', STEP.ReversePackagePath, 1) - 1)) AS PackageName            
FROM msdb.dbo.sysjobs JOB       
CROSS APPLY (
                 SELECT
                    REVERSE(LEFT(command, CHARINDEX('.dtsx', command, 1) - 1)) ReversePackagePath
 FROM  msdb.dbo.sysjobsteps                    
 WHERE
                    job_id = JOB.job_id
                    AND subsystem = 'SSIS'

 ) STEP
)  JobList
INNER JOIN [msdb]..[sysssispackages] p ON p.name = JobList.PackageName
CROSS APPLY (   
                SELECT
                    g.ConnectionManagerName,
                    g.ConnectionType,
                    g.ConnectionString
                    FROM
                    (   
                        SELECT
                            f.PackageXml,
                                                      CAST(CAST(f.PackageXml.query(N'/DTS:Executable[1]/DTS:Property[@DTS:Name="PackageFormatVersion"]/text()') AS nvarchar(25)) AS int) AS PackageXmlVersion
FROM (SELECT CAST(CAST(p.packagedata AS varbinary(MAX)) AS xml) AS PackageXml) f
                    ) px
                    CROSS APPLY
                    (
                        SELECT

CAST(x.query(N'./DTS:Property[@DTS:Name="ObjectName"]/text()') AS nvarchar(256)) AS ConnectionManagerName,
CAST(x.query(N'./DTS:Property[@DTS:Name="CreationName"]/text()') AS nvarchar(512)) AS ConnectionType,               
CAST(x.query(N'./DTS:ObjectData[1]/DTS:ConnectionManager[1]/DTS:Property[@DTS:Name="ConnectionString"]/text()') AS nvarchar(2048)) AS ConnectionString
FROM px.PackageXml.nodes(N'/DTS:Executable[1]/DTS:ConnectionManager') cm(x)
                        WHERE px.PackageXmlVersion = 3 /* 2008 R2 */
                        UNION ALL
SELECT
                            x.value(N'@DTS:ObjectName', 'nvarchar(256)'),
                            x.value(N'@DTS:CreationName', 'nvarchar(512)'),
                            (

SELECT
                                    y.value(N'@DTS:ConnectionString', 'nvarchar(2048)')


FROM x.nodes(N'./DTS:ObjectData[1]/DTS:ConnectionManager[1]') cp(y)
                            )

FROM px.PackageXml.nodes(N'/DTS:Executable[1]/DTS:ConnectionManagers[1]/DTS:ConnectionManager') cm(x)
                        WHERE px.PackageXmlVersion = 6 /* 2012 */
                ) g
        ) pd

 WHERE
        (p.packageformat = 0) AND /* XML format */
        (p.isencrypted = 0) AND
        (p.folderid = '00000000-0000-0000-0000-000000000000'); 

0 个答案:

没有答案