I have a column that contains a CRON expression that represents how often a user has to perform a task. I would like to build a view that lists the date and things to do for a given user. But I need to calculate my next CRON occurrence in a datetime in T-SQL. How interpreted my expression CRON in SQL?
example: column value = [0 30 8 1 *?]
I would write: SELECT CrontabSchedule ( '0 30 8 1 *?', GETDATE ()) FROM dbo.UserTasks
Someone has a solution ?
Meaning of cron expression 0 * * * * *? I think it means the scheduler is expected to run every seconds.
Expand SQL Server Agent, expand Jobs, right-click the job you want to schedule, and click Properties. Select the Schedules page, and then click New. In the Name box, type a name for the new schedule. Clear the Enabled check box if you do not want the schedule to take effect immediately following its creation.
CronMaker is a simple application which helps you to build cron expressions. CronMaker uses Quartz open source scheduler. Generated expressions are based on Quartz cron format. For your feedback send email to [email protected]. Generate cron expression.
There is no built in function within SQL server to genrate Next date based on Cron expression. Only way would be, implemeting cron exprssions in C# and genrate it as dll,then regsiter DLL with SQL server CLR.
Refernces: https://social.msdn.microsoft.com/Forums/en-US/3e0ebe5a-d452-4893-bcef-0a1e2520c076/convert-cron-expression-to-datetime?forum=transactsql
https://github.com/atifaziz/NCrontab/wiki/SQL-Server-Crontab
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With