According to your description, if you want to run query daily and set the time , I suggest you that you could create the schedule for the sql jobs. Sqlserver will do the job by following the schedule.You could follow the steps as below:
Expand the SQL Server Agent node and right click the Jobs node in SQL Server Agent and select'New Job'
In the'New Job'window enter the name of the job and a description on the'General'tab.
Select'Steps'on the left hand side of the window and click'New'at the bottom.
In the'Steps'window enter a step name and select the database you want the query to run against.
Paste in the T-SQL command you want to run into the Command window and click'OK'.
Click on the'Schedule'menu on the left of the New Job window and enter the schedule information (e.g. daily and a time).
Member
10 Points
145 Posts
transfer backup code to batch
Mar 14, 2019 11:47 AM|thepast|LINK
hi people I wrote this code to backup my database
I want to put it in .bat file to schedule it and run it at 8:00 PM everyday
How can I make that
All-Star
53711 Points
24037 Posts
Re: transfer backup code to batch
Mar 14, 2019 01:13 PM|mgebhard|LINK
As recommend in your similar thread, use osql or cmdsql to execute SQL via the command line.
https://forums.asp.net/p/2153657/6254240.aspx?Re+Batch+to+backup+database
Simply save the text file as a filename.bat and execute the bat file using Windows Task Scheduler or SQL agent.
Participant
1300 Points
522 Posts
Re: transfer backup code to batch
Mar 15, 2019 02:57 AM|Wei Zhang|LINK
Hi thepast,
According to your description, if you want to run query daily and set the time , I suggest you that you could create the schedule for the sql jobs. Sqlserver will do the job by following the schedule.You could follow the steps as below:
Expand the SQL Server Agent node and right click the Jobs node in SQL Server Agent and select
'New Job'
In the
'New Job'
window enter the name of the job and a description on the'General'
tab.Select
'Steps'
on the left hand side of the window and click'New'
at the bottom.In the
'Steps'
window enter a step name and select the database you want the query to run against.Paste in the T-SQL command you want to run into the Command window and click
'OK'
.Click on the
'Schedule'
menu on the left of the New Job window and enter the schedule information (e.g. daily and a time).Click
'OK'
- and that should be it.Here is the link, I hope it could help you.
https://stackoverflow.com/questions/5471080/how-to-schedule-a-job-for-sql-query-to-run-daily
Best Regards
Wei Zhang