问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

怎么查看JOB的执行情况

发布网友 发布时间:2022-04-10 11:30

我来回答

2个回答

懂视网 时间:2022-04-10 15:52

testtemp as( SELECT sch.job_id,--his.[server] as InstanceName CONVERT(nvarchar(150),his.[server]) as InstanceName ,--job.NAME as job_name CONVERT(nvarchar(150),job.NAME) as job_name ,job.[enabled] as job_enabled , --schs.[name] AS [ScheduleName] CONVERT(nvarchar(150),schs.[name]) as ScheduleName , CASE schs.[enabled] WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' else 'unknow' END AS [IsEnabled] , CASE WHEN [freq_type] = 64 THEN 'Start automatically when SQL Server Agent starts' WHEN [freq_type] = 128 THEN 'Start whenever the CPUs become idle' WHEN [freq_type] IN (4,8,16,32) THEN 'Recurring' WHEN [freq_type] = 1 THEN 'One Time' else 'unkown' END [ScheduleType] , CASE [freq_type] WHEN 1 THEN 'One Time' WHEN 4 THEN 'Daily' WHEN 8 THEN 'Weekly' WHEN 16 THEN 'Monthly' WHEN 32 THEN 'Monthly - Relative to Frequency Interval' WHEN 64 THEN 'Start automatically when SQL Server Agent starts' WHEN 128 THEN 'Start whenever the CPUs become idle' else 'unkown' END [Occurrence] , CASE [freq_type] WHEN 4 THEN 'Occurs every ' + CAST([freq_interval] AS VARCHAR(3)) + ' day(s)' WHEN 8 THEN 'Occurs every ' + CAST([freq_recurrence_factor] AS VARCHAR(3)) + ' week(s) on ' + CASE WHEN [freq_interval] & 1 = 1 THEN 'Sunday' ELSE '' END + CASE WHEN [freq_interval] & 2 = 2 THEN ', Monday' ELSE '' END + CASE WHEN [freq_interval] & 4 = 4 THEN ', Tuesday' ELSE '' END + CASE WHEN [freq_interval] & 8 = 8 THEN ', Wednesday' ELSE '' END + CASE WHEN [freq_interval] & 16 = 16 THEN ', Thursday' ELSE '' END + CASE WHEN [freq_interval] & 32 = 32 THEN ', Friday' ELSE '' END + CASE WHEN [freq_interval] & 64 = 64 THEN ', Saturday' ELSE '' END WHEN 16 THEN 'Occurs on Day ' + CAST([freq_interval] AS VARCHAR(3)) + ' of every ' + CAST([freq_recurrence_factor] AS VARCHAR(3)) + ' month(s)' WHEN 32 THEN 'Occurs on ' + CASE [freq_relative_interval] WHEN 1 THEN 'First' WHEN 2 THEN 'Second' WHEN 4 THEN 'Third' WHEN 8 THEN 'Fourth' WHEN 16 THEN 'Last' END + ' ' + CASE [freq_interval] WHEN 1 THEN 'Sunday' WHEN 2 THEN 'Monday' WHEN 3 THEN 'Tuesday' WHEN 4 THEN 'Wednesday' WHEN 5 THEN 'Thursday' WHEN 6 THEN 'Friday' WHEN 7 THEN 'Saturday' WHEN 8 THEN 'Day' WHEN 9 THEN 'Weekday' WHEN 10 THEN 'Weekend day' END + ' of every ' + CAST([freq_recurrence_factor] AS VARCHAR(3)) + ' month(s)' else 'unknown' END AS [Recurrence] , CASE [freq_subday_type] WHEN 1 THEN 'Occurs once at ' + STUFF( STUFF(RIGHT('000000' + CAST([active_start_time] AS VARCHAR(6)), 6) , 3, 0, ':') , 6, 0, ':') WHEN 2 THEN 'Occurs every ' + CAST([freq_subday_interval] AS VARCHAR(3)) + ' Second(s) between ' + STUFF( STUFF(RIGHT('000000' + CAST([active_start_time] AS VARCHAR(6)), 6) , 3, 0, ':') , 6, 0, ':') + ' & ' + STUFF( STUFF(RIGHT('000000' + CAST([active_end_time] AS VARCHAR(6)), 6) , 3, 0, ':') , 6, 0, ':') WHEN 4 THEN 'Occurs every ' + CAST([freq_subday_interval] AS VARCHAR(3)) + ' Minute(s) between ' + STUFF( STUFF(RIGHT('000000' + CAST([active_start_time] AS VARCHAR(6)), 6) , 3, 0, ':') , 6, 0, ':') + ' & ' + STUFF( STUFF(RIGHT('000000' + CAST([active_end_time] AS VARCHAR(6)), 6) , 3, 0, ':') , 6, 0, ':') WHEN 8 THEN 'Occurs every ' + CAST([freq_subday_interval] AS VARCHAR(3)) + ' Hour(s) between ' + STUFF( STUFF(RIGHT('000000' + CAST([active_start_time] AS VARCHAR(6)), 6) , 3, 0, ':') , 6, 0, ':') + ' & ' + STUFF( STUFF(RIGHT('000000' + CAST([active_end_time] AS VARCHAR(6)), 6) , 3, 0, ':') , 6, 0, ':') else 'unkown' END [Frequency] ,job.category_id ,job.[description] as job_description ,his.sql_message_id ,his.sql_severity ,his.[message] as job_message ,his.run_status as last_run_status ,job.date_created ,'LastRunDateTime' = CASE WHEN his.run_date = 0 THEN null ELSE msdb.dbo.agent_datetime(his.run_date, his.run_time) END ,'NextRunDateTime' = CASE WHEN sch.next_run_date = 0 THEN null ELSE msdb.dbo.agent_datetime(sch.next_run_date, sch.next_run_time) END ,dateadd(second,(run_duration / 10000 * 3600 + (run_duration / 100) % 100 * 60 + run_duration % 100),msdb.dbo.agent_datetime(his.run_date, his.run_time)) as LastRunFinishDateTime ,((run_duration / 10000 * 3600 + (run_duration / 100) % 100 * 60 + run_duration % 100)) AS 'RunDurationSeconds' FROM msdb..sysjobschedules AS sch INNER JOIN msdb..sysjobs AS job ON sch.job_id = job.job_id inner join msdb..sysschedules as schs on sch.schedule_id=schs.schedule_id LEFT JOIN (select hi.* from msdb..sysjobhistory as hi inner join (select job_id,max(instance_id) as instance_id from msdb..sysjobhistory jh where jh.step_id = 0 GROUP BY jh.job_id) as jh on hi.job_id = jh.job_id and hi.instance_id = jh.instance_id) AS his ON his.job_id = job.job_id ) select isnull(job_id, null) as job_id, isnull(InstanceName,'')as InstanceName, isnull(job_name,'')as job_name, isnull(job_enabled,0) as job_enabled, isnull(ScheduleName,'')as ScheduleName, isnull(IsEnabled,'')as IsEnabled, isnull(ScheduleType, '')as ScheduleType, isnull(Occurrence, '')as Occurrence, isnull(Recurrence,'')as Recurrence, isnull(Frequency,'')as Frequency, isnull(category_id, 0)as category_id, isnull(job_description , '')as job_description, isnull(sql_message_id, 0)as sql_message_id, isnull(sql_severity,0)as sql_severity, isnull(job_message , '')as job_message, isnull(last_run_status,0)as last_run_status, isnull(date_created , '1900-01-01')as date_created, isnull(LastRunDateTime,'1900-01-01')as LastRunDateTime, isnull(NextRunDateTime,'1900-01-01')as NextRunDateTime, isnull(LastRunFinishDateTime,'1900-01-01')as LastRunFinishDateTime, isnull(RunDurationSeconds,0)as RunDurationSeconds from testtemp where job_name<>'syspolicy_purge_history'

获取结果:
技术分享图片

技术分享图片

sqlserver获取代理服务作业job的执行情况

标签:let   执行   post   分享   desc   ken   code   结果   seve   

热心网友 时间:2022-04-10 13:00

select J.name 作业名称,P.step_id'步骤编号',P.step_name'步骤名称',P.command'执行命令',
case freq_type
when 1 then '只执行一次'
when 4 then '每日'
when 8 then '每周'
when 16 then '每月'
when 32 then '每月'
when 64 then '当 SQLServerAgent 服务启动时运行'
when 128 then '计算机空闲时运行'
else '' end 频率,
case freq_type
when 8 then case when freq_interval&1 = 1 then '星期日' else '' end +
case when freq_interval&2 = 2 then '星期一' else '' end +
case when freq_interval&4 = 4 then '星期二' else '' end +
case when freq_interval&8 = 8 then '星期三' else '' end +
case when freq_interval&16=16 then '星期四' else '' end +
case when freq_interval&32=32 then '星期五' else '' end +
case when freq_interval&64=64 then '星期六' else '' end
when 16 then '第'+ltrim(str(freq_interval))+'天'
else '' end 指定 ,
stuff(stuff(right('000000'+ltrim(str(active_start_time)),6),3,0,':'),6,0,':') 启动时间,
case freq_subday_type
when 4 then '每'+ltrim(str(freq_subday_interval))+'分钟'
when 8 then '每'+ltrim(str(freq_subday_interval))+'小时'
else '' end '间隔 ',
case J.enabled
when 0 then '禁用'
when 1 then '启用'
else '' end '状态',
case P.last_run_outcome
when 0 then '失败'
when 1 then '成功'
else '' end '上次执行' ,
P.last_run_ration'执行时间(秒)',
str(last_run_date)+' '+stuff(stuff(right('000000'+ltrim(str(last_run_time)),6),3,0,':'),6,0,':') '上次启动时间'
from msdb.dbo.sysjobscheles S
inner join msdb.dbo.sysjobs J on S.job_id = J.job_id
inner join msdb.dbo.sysjobsteps P on S.job_id = P.job_id
order by 启动时间
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
书包放在教室一晚上没事吗 格力空调三滴水的模式 将不快乐藏于心的伤感签名 人生如梦我失眠 缓刑期间犯罪还可以判缓吗 缓刑期间再有形势案件还可以判缓吗?对方不追久了赔了钱了, 缓刑期间又犯新罪还可以缓吗 由于老板拖欠工资并且把工资算错 我把货款留给自己用 然后走人去外省... 如果老板欠我工资,我拿了他的货款算不算职务侵占 职务侵占3万元货款已全数退回,会怎样量刑? 荞麦皮枕头多久换一次 荞麦枕头多久更换最合适 请问可以进行薄膜材料气体透过率测试 的机构 祥富(中山)塑料薄膜包装有限公司怎么样? 昨天请了一对佛灯 可晚上做梦 梦到佛龛前佛灯没亮 一下子就醒了 电信电视ip地址获取失败,怎么办 梦见两展佛灯? 未获取到IP地址,请检测网络,电视看不了? 梦见好多佛像佛龛佛灯? 英雄联盟-掉线后无法连接原本的对局 首次提出连锁遗传规律,建立基因的染色体理论的人是谁 为什么英雄联盟进不去?一直显示无法连接服务器。 遗传学的三大遗传规律的区别和联系 染色体遗传学有哪些方面的实践意义 lol一局打一半突然掉线了,重连提示无法连接服务器,重启电脑后发现比赛记录里没有那把,怎么回事?? 萨顿提出的遗传的染色体假说是什么 lol崩溃以后对局没了怎么回事 人类性别遗传“XY性染色体理论”是真理吗 请简述遗传学三种基本定律及其染色体基础 英雄联盟进入游戏显示无法连接服务器,点击重试也没用。 伴性遗传的发现对染色体遗传理论的确立有何作用 英雄联盟进入游戏无法连接连接,重启过后这局游戏没有了比赛也没记录游戏! 用漂白剂刷鞋好吗? 电脑开机灯亮一下然后就熄灯无法启动怎么回事 请问钩毛线拖鞋的短针,中长针,长针分别是怎样钩 怎样才能醒酒快一点 怎么样的方法醒酒最好最快 ? 请问,怎么样比较容易醒酒?求大神帮助 怎么样才能醒酒快 怎样才能很快的醒酒? 怎样才能快速醒酒 腾讯视频会员号通过什么途径代理获取来卖的 怎样才能立马醒酒 怎么样才能醒酒快? 开通腾讯视频Vip用哪些集分可代购? 怎样才能快速解酒 谁有腾讯视频的会员卖 一年的 不要贵的 跪求一个可以流畅放《憨豆先生》的软件,高分! 哪里有腾讯视频会员? 如何通过程序控制sql server中Job的执行周期等参数 憨豆先生电影手机怎么下载 有什么软件可以下载憨豆先生的吗??手机的!!!谢了!!