从 msdb.dbo.sysjobhistory 获取最近 24 小时的作业记录
我想编写一个查询来从“msdb.dbo.sysjobhistory”表中获取过去 24 小时的作业记录,但我无法获取,因为我得到的“run_date”和“run_time”列以数字形式返回。如何将“run_date”和“run_time”列转换为日期时间变量,并使用它来获取最近 24 小时的作业历史记录?
I want write a query to get the last 24 hours worth of job record from the "msdb.dbo.sysjobhistory" table, but I can't get because I get the "run_date" and "run_time" columns are returned as a number. How can I convert the "run_date" and "run_time" columns into a datetime variable, and use this to get the last 24 hour job history?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
查看 这篇文章 - 它展示了如何从
sysjobhistory
中“解码”那些run_date
列。您应该能够通过如下查询获取过去 24 小时内的条目:
Check out this post - it shows how to "decode" those
run_date
columns fromsysjobhistory
.You should be able to get the entries from the last 24 hours with a query something like this:
对于 2000 之后的数据库,您可以调用 msdb 数据库中的一个函数来返回日期时间:
如果您使用的是 sql 2000,您可以从更高版本复制该函数的源代码并在 2000 的实例中创建它。希望我能将这一切归功于我,但我最初在这里找到它: mssqltips.com
For databases after 2000, there is a function in the msdb database you can call that will return datetime:
If you are using sql 2000, you can copy the source of that function from a later version and create it in your instance of 2000. I wish I could take credit for all of this, but I originally found it here: mssqltips.com
我的一位同事指出,其他给定的解决方案只能找到我们在 24 小时前(或更短时间)开始的作业,而不是 24 小时完成的作业之前(或更短)。他提出了以下内容来定位已完成的工作:
我相信其中一部分来自博客,但我们无法找到它,当我找到它时,我也会链接它......
A co-worker of mine pointed out that the other given solutions only find jobs that we're started 24 hours ago (or less), not jobs that were completed 24 hours ago (or less). He proposed something along the lines of the following to location completed jobs:
I believe part of this comes from a blog, but we cannot locate it, when I do I'll link that as well...