Bashirsk CFC Bashirsk CFC - 4 months ago 9
SQL Question

Incorrect syntax near the keyword 'inner'

I am trying to display the scheduled jobs with a name, status and description. This works very well, however when i try to sort it using order by ScheduledName, i get an error telling me i have an incorrect syntax and i have no idea how to fix it.

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 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

Answer

You use an incorrect Syntax. Change to:

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