关键字'inner'附近的语法不正确

时间:2016-08-01 11:57:38

标签: sql sql-server database

我正在尝试显示具有名称,状态和说明的预定作业。这非常有效,但是当我尝试使用ScheduledName的顺序对其进行排序时,我收到一个错误,告诉我语法不正确,我不知道如何修复它。

SELECT * FROM sysjobs Job

SELECT * FROM sysschedules 

SELECT * FROM sysjobschedules

SELECT 
    SC.name AS ScheduledName, Job.name AS JobName, 
    Job.enabled AS JobStatus, Job.description AS JobDescription 
FROM 
    sysjobs Job 
ORDER BY 
    ScheduledName;
INNER JOIN
    sysjobschedules SCH ON Job.job_id = SCH.job_id
INNER JOIN
    sysschedules SC ON SC.schedule_id = SCH.schedule_id

4 个答案:

答案 0 :(得分:1)

您使用的语法不正确。改为:

USE msdb
GO

SELECT * FROM sysjobs Job;

SELECT * FROM sysschedules; 

SELECT * FROM sysjobschedules;

SELECT SC.name AS ScheduledName, Job.name AS JobName, Job.enabled AS JobStatus, Job.description AS JobDescription FROM sysjobs Job 
inner join sysjobschedules SCH
on Job.job_id=SCH.job_id
inner join sysschedules SC
on SC.schedule_id=SCH.schedule_id
ORDER BY ScheduledName

答案 1 :(得分:0)

您的查询是:

SELECT SC.name AS ScheduledName, Job.name AS JobName, Job.enabled AS JobStatus, Job.description AS JobDescription
FROM sysjobs Job
ORDER BY SC.name;

分号终止查询。

删除分号后,还需要将ORDER BY移到最后:

SELECT SC.name AS ScheduledName, Job.name AS JobName,
       Job.enabled AS JobStatus, Job.description AS JobDescription
FROM sysjobs Job inner join
     sysjobschedules SCH on
     Job.job_id = SCH.job_id inner join
     sysschedules SC
     on SC.schedule_id = SCH.schedule_id
ORDER BY SC.name;

答案 2 :(得分:0)

SELECT SC.NAME AS ScheduledName
    ,Job.NAME AS JobName
    ,Job.enabled AS JobStatus
    ,Job.description AS JobDescription
FROM sysjobs Job
INNER JOIN sysjobschedules SCH ON Job.job_id = SCH.job_id
INNER JOIN sysschedules SC ON SC.schedule_id = SCH.schedule_id
ORDER BY SC.NAME

答案 3 :(得分:0)

Order By应该在最后

USE msdb
GO

SELECT * FROM sysjobs Job

SELECT * FROM sysschedules 

SELECT * FROM sysjobschedules

SELECT 
   SC.name AS ScheduledName, 
   Job.name AS JobName, 
   Job.enabled AS JobStatus, 
   Job.description AS JobDescription 
FROM sysjobs Job 
inner join sysjobschedules SCH
on Job.job_id=SCH.job_id
inner join sysschedules SC
on SC.schedule_id=SCH.schedule_id
ORDER BY ScheduledName;