使用 T-SQL 获取 SSIS 包名称、作业名称和描述

Using T-SQL to get the SSIS Package name, job name and description(使用 T-SQL 获取 SSIS 包名称、作业名称和描述)
本文介绍了使用 T-SQL 获取 SSIS 包名称、作业名称和描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 SQL Server 中获取以下信息:

I'm trying to get the following information out of SQL Server:

  • 所有 SSIS 作业代理名称.
  • SSIS 包名称.
  • [可选但很高兴] SSIS 工作代理描述.

我可以使用下表毫无问题地提取所有这 3 条信息:

I'm able to pull all 3 of these pieces of information with no problems using the following tables:

  • msdb.dbo.sysjobs 为我提供了工作名称和工作描述.
  • msdb.dbo.sysssispackages 为我提供了 SSIS 包名称.

不幸的是,我无法找到这 2 个表之间的相关性,无法将所有 3 条信息放在一起.

Unfortunately I'm not able to find a correlation between those 2 tables to gets me all 3 pieces of information together.

有什么想法吗?谢谢!

推荐答案

这似乎是 Microsoft 的一个明显漏洞 - 如果 PackageId 存储在 msdb.dbo.sysjobsteps 表,而不必解析来自 Command 列的信息.正如 OP 正确指出的那样,当包名称相同时,这可能会出现问题.无论如何,我一直在研究提供以下内容的查询:

This appears to be a glaring hole by Microsoft - it would be much nicer if the PackageId were stored in the msdb.dbo.sysjobsteps table, instead of having to parse the information from the Command column. As the OP correctly pointed out, this can be problematic when package names are the same. At any rate, I have been working on a query to provide the following:

  1. 职位名称
  2. 步骤名称
  3. 包文件夹路径

-- 获取作业指向的包的文件夹路径.这将所有内容结合在一起.

-- Get the folder path of the package that a job points to. This brings it all together.

;WITH CTE1 AS (
    SELECT 
        J.job_id
        ,JobName = J.name
        ,JS.step_id, JS.step_name, JS.command
        ,StartIndex = 
            CASE 
                WHEN JS.command LIKE '/DTS%' OR JS.command LIKE '/SQL%' OR JS.command LIKE '/ISSERVER%' THEN CHARINDEX('\',JS.command, CHARINDEX('\',JS.command) + 1) --'
                WHEN JS.command LIKE '/SERVER%' THEN CHARINDEX('"', JS.Command, CHARINDEX(' ',command, CHARINDEX(' ',command) + 1) + 1) + 1
                ELSE 0
            END
        ,EndIndex = 
            CASE 
                WHEN JS.command LIKE '/DTS%' OR JS.command LIKE '/SQL%'  OR JS.command LIKE '/ISSERVER%' 
                    THEN  CHARINDEX('"',JS.command, CHARINDEX('\',JS.command, CHARINDEX('\',JS.command) + 1)) --'
                        - CHARINDEX('\',JS.command, CHARINDEX('\',JS.command) + 1) - 1 --'
                WHEN JS.command LIKE '/SERVER%' 
                    THEN  CHARINDEX('"',command, CHARINDEX('"', JS.Command, CHARINDEX(' ',command, CHARINDEX(' ',command) + 1) + 1) + 1)
                        - CHARINDEX('"', JS.Command, CHARINDEX(' ',command, CHARINDEX(' ',command) + 1) + 1) - 1
                ELSE 0
            END
    FROM msdb.dbo.sysjobsteps JS
    INNER JOIN msdb.dbo.sysjobs J
        ON JS.job_id = J.job_id
    WHERE JS.subsystem = 'SSIS'
)    
SELECT 
    C1.job_id
    , C1.JobName
    , C1.step_id
    , C1.step_name
    , PackageFolderPath = 
        CASE 
            WHEN C1.command LIKE '/DTS%' OR C1.command LIKE '/ISSERVER%' THEN SUBSTRING(C1.command, C1.StartIndex, C1.EndIndex)
            WHEN C1.command LIKE '/SQL%' THEN '\MSDB' + SUBSTRING(C1.command, C1.StartIndex, C1.EndIndex)
            WHEN C1.command LIKE '/SERVER%' THEN '\MSDB\' + SUBSTRING(C1.command, C1.StartIndex, C1.EndIndex)
            ELSE NULL
        END
    , C1.command
FROM CTE1 C1
ORDER BY C1.job_id, C1.step_id

这篇关于使用 T-SQL 获取 SSIS 包名称、作业名称和描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)