我有一个存储过程返回一些结果集。我创建了一个表,我在此表中插入存储过程的结果。现在我想要的是,我想每隔30分钟刷新存储过程以及表格。
Here is my stored proc.,
USE [my_DB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[sp_1]
@Week int = 1,
@Year int = 2014
AS
BEGIN
declare @current_week int
set @current_week = datepart (week, getdate())
while @Week <= @current_week
begin
truncate table [my_DB].[dbo].[tb_name]
insert into [my_DB].[dbo].[tb_name]
exec sp_2 @Week,@Year
select @Week as Week_Number,* from [my_DB].[dbo].[tb_name] (nolock)
set @Week = @Week + 1
end
END
我是如何实现这一目标的?一个例子会更有帮助。
感谢。
答案 0 :(得分:1)
最佳答案是配置每30分钟运行一次的作业,但您也可以这样做:
Salto:
Exec sp_1;
Waitfor Delay '00:30:00';
Goto Salto;