I have the following situation I am working on with the majority of the issue solved. I currently the following folders and files existing on a machine.
C:\foo\foo.sql
C:\foo\foo.bat
"foo.sql" - is a script file that has a very simple line in it:
EXEC uspUpdateCounts
"foo.bat" - invokes SQLCMD to call execute foo.sql and log any output from the stored procedure called to a text file with the current time and date stamp (this will only run once per day):
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE" -S SvrNme -E -d dbName -i C:\foo\foo.sql -o "C:\foo\fooOutput_%date:~-4,4%%date:~-10,2%%date:~-7,2%.txt"
I am currently using a windows scheduled task to kick off foo.bat I would like to know if there is a way I can script the time to happen randomly every day to run between 6AM and 1PM PST. I have messed around with some time components in scripts I have found here and there, but I cannot get it to randomize the minute. I can get the hour but its not very reliable but at this point I am completely lost. If someone can help me with this solution and also explain the solution, that would be great. I am not just looking for the answer but to learn as well.