开发者

Check time in stored procedure

I have a stored procedure that takes a lot of time to execute. We want it to execute during the night, but it has to check for the current time every now and then, and at a given time it h开发者_运维技巧as to stop executing. How do I do that? Please provide me with the code I can use in my stored procedure. We are using Microsoft SQL Server 2005.


You can get the current date:

SELECT GETDATE()

Stop executing:

If @date > GETDATE()
    RETURN --Exits procedure

Where @date is the date/time when you want to stop executing


Create Maintenance plan and sprecify start time for it. Create "Execute T-SQL statement task" in this plan and specify execution timeout for it (in seconds).


Why woudl you want to exist a proc that is not finished? Wouldn't you be leaving things in a bad state as far as data integrity or rolling back all the work you just did??

Wouldn't it be a better solution to try to improve the performance of the proc?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜