我正在尝试从 SQL Server 中获取以下信息:
I'm trying to get the following information out of SQL Server:
我可以使用下表毫无问题地提取所有这 3 条信息:
I'm able to pull all 3 of these pieces of information with no problems using the following tables:
不幸的是,我无法找到这 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:
-- 获取作业指向的包的文件夹路径.这将所有内容结合在一起.
-- 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 包名称、作业名称和描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!