Sql语句 循环调用存储过程 设置1秒执行一次!

  • Post author:
  • Post category:其他


一个日结的存储过程P_Wms_StockDailyState 参数是格式是’yyyy-MM-dd’

这个存储过程必须一天结算一次!比如在每天的几点几时几分执行这个存储过程!

现在呢 想把之前的也执行掉!意思就是

我从 2012-5-1 开始 执行到 今天之前的2012-11-15 设置1秒执行一次!

当执行到今天之前后停止! 后面 就是一天的某个时间 点执行一次!


1.--测试结果:


declare


@dt


varchar


(30),@today


varchar


(30)

select


@dt =


'2012-05-01'


,@today=


left


(


convert


(


varchar


(30),getdate(),120),10)


while @dt<@today

begin



print


'exec P_Wms_StockDailyState '


''


+@dt+


''


''



set


@dt=


left


(


convert


(


varchar


(30),DATEADD(


day


,1,@dt),120),10)



--waitfor delay '00:00:01'

end



--输出:

exec


P_Wms_StockDailyState


'2012-05-01'

exec


P_Wms_StockDailyState


'2012-05-02'

exec


P_Wms_StockDailyState


'2012-05-03'

exec


P_Wms_StockDailyState


'2012-05-04'

exec


P_Wms_StockDailyState


'2012-05-05'

exec


P_Wms_StockDailyState


'2012-05-06'

exec


P_Wms_StockDailyState


'2012-05-07'

exec


P_Wms_StockDailyState


'2012-05-08'

exec


P_Wms_StockDailyState


'2012-05-09'

exec


P_Wms_StockDailyState


'2012-05-10'

exec


P_Wms_StockDailyState


'2012-05-11'

exec


P_Wms_StockDailyState


'2012-05-12'

exec


P_Wms_StockDailyState


'2012-05-13'

exec


P_Wms_StockDailyState


'2012-05-14'

exec


P_Wms_StockDailyState


'2012-05-15'

exec


P_Wms_StockDailyState


'2012-05-16'

exec


P_Wms_StockDailyState


'2012-05-17'

exec


P_Wms_StockDailyState


'2012-05-18'

exec


P_Wms_StockDailyState


'2012-05-19'

exec


P_Wms_StockDailyState


'2012-05-20'

exec


P_Wms_StockDailyState


'2012-05-21'

exec


P_Wms_StockDailyState


'2012-05-22'

exec


P_Wms_StockDailyState


'2012-05-23'

exec


P_Wms_StockDailyState


'2012-05-24'

exec


P_Wms_StockDailyState


'2012-05-25'

exec


P_Wms_StockDailyState


'2012-05-26'

exec


P_Wms_StockDailyState


'2012-05-27'

exec


P_Wms_StockDailyState


'2012-05-28'

exec


P_Wms_StockDailyState


'2012-05-29'

exec


P_Wms_StockDailyState


'2012-05-30'

exec


P_Wms_StockDailyState


'2012-05-31'

exec


P_Wms_StockDailyState


'2012-06-01'

exec


P_Wms_StockDailyState


'2012-06-02'

exec


P_Wms_StockDailyState


'2012-06-03'

exec


P_Wms_StockDailyState


'2012-06-04'

exec


P_Wms_StockDailyState


'2012-06-05'

exec


P_Wms_StockDailyState


'2012-06-06'

exec


P_Wms_StockDailyState


'2012-06-07'

exec


P_Wms_StockDailyState


'2012-06-08'

exec


P_Wms_StockDailyState


'2012-06-09'

exec


P_Wms_StockDailyState


'2012-06-10'

exec


P_Wms_StockDailyState


'2012-06-11'

exec


P_Wms_StockDailyState


'2012-06-12'

exec


P_Wms_StockDailyState


'2012-06-13'

exec


P_Wms_StockDailyState


'2012-06-14'

exec


P_Wms_StockDailyState


'2012-06-15'

exec


P_Wms_StockDailyState


'2012-06-16'

exec


P_Wms_StockDailyState


'2012-06-17'

exec


P_Wms_StockDailyState


'2012-06-18'

exec


P_Wms_StockDailyState


'2012-06-19'

exec


P_Wms_StockDailyState


'2012-06-20'

exec


P_Wms_StockDailyState


'2012-06-21'

exec


P_Wms_StockDailyState


'2012-06-22'

exec


P_Wms_StockDailyState


'2012-06-23'

exec


P_Wms_StockDailyState


'2012-06-24'

exec


P_Wms_StockDailyState


'2012-06-25'

exec


P_Wms_StockDailyState


'2012-06-26'

exec


P_Wms_StockDailyState


'2012-06-27'

exec


P_Wms_StockDailyState


'2012-06-28'

exec


P_Wms_StockDailyState


'2012-06-29'

exec


P_Wms_StockDailyState


'2012-06-30'

exec


P_Wms_StockDailyState


'2012-07-01'

exec


P_Wms_StockDailyState


'2012-07-02'

exec


P_Wms_StockDailyState


'2012-07-03'

exec


P_Wms_StockDailyState


'2012-07-04'

exec


P_Wms_StockDailyState


'2012-07-05'

exec


P_Wms_StockDailyState


'2012-07-06'

exec


P_Wms_StockDailyState


'2012-07-07'

exec


P_Wms_StockDailyState


'2012-07-08'

exec


P_Wms_StockDailyState


'2012-07-09'

exec


P_Wms_StockDailyState


'2012-07-10'

exec


P_Wms_StockDailyState


'2012-07-11'

exec


P_Wms_StockDailyState


'2012-07-12'

exec


P_Wms_StockDailyState


'2012-07-13'

exec


P_Wms_StockDailyState


'2012-07-14'

exec


P_Wms_StockDailyState


'2012-07-15'

exec


P_Wms_StockDailyState


'2012-07-16'

exec


P_Wms_StockDailyState


'2012-07-17'

exec


P_Wms_StockDailyState


'2012-07-18'

exec


P_Wms_StockDailyState


'2012-07-19'

exec


P_Wms_StockDailyState


'2012-07-20'

exec


P_Wms_StockDailyState


'2012-07-21'

exec


P_Wms_StockDailyState


'2012-07-22'

exec


P_Wms_StockDailyState


'2012-07-23'



2.--这是执行的SQL语句!

DECLARE


@return_value


int


,


@message nvarchar(4000)

EXEC


@return_value = P_Wms_StockDailyState




@message = @message


OUTPUT

SELECT


@message


as



N



'@message'

SELECT


'Return Value'


= @return_value

GO



版权声明:本文为jindou910101原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。