INSERT data from SQL table to EXCEL

INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=E:\MSSQL\Reports\JobSchedules.xls;',
'SELECT JobName, ScheduleName, next_run_date FROM [Sheet1$]')

select j.name JobName, s.name ScheduleName,
 next_run_date
from msdb..sysjobs j
join msdb..sysjobschedules s
 on j.job_id = s.job_id
where j.enabled = 1
 and s.enabled = 1
ORDER BY
 j.name
GO

— Note:
—  Requires E:\MSSQL\Reports\JobSchedules.xls to already exist with the correct columns.

Comments are closed.

Post Navigation