我打电话的程序日复一日。我需要传递/迭代一天到当前日期到它执行操作的过程。可以帮助一些。这是我尝试的样本,但它无法正常工作。我是初学者。
USE [aaa]
GO
DECLARE @return_value int
DECLARE @VarDate1 Datetime ='2015-09-30'
DECLARE @VarDate2 Datetime ='2015-09-30'
WHILE (@VarDate2 <= '2015-12-10')
BEGIN
EXEC @return_value = [dbo].[procname]
@tday1 = @VarDate1 ,
@tday2 = @VarDate2
SET @VarDate2 = DATEADD(DAY, 1, @VarDate2)
set @VarDate1 = @VarDate2
SELECT 'Return Value' = @return_value
END
GO
答案 0 :(得分:-1)
通过检查代码,您在尝试设置@ VarDate1和@ VarDate2的值时可能会收到错误。请尝试以下代码:
DECLARE @return_value int
DECLARE @VarDate1 Datetime = CAST('20150930 00:00:00' AS DATETIME)
DECLARE @VarDate2 Datetime = CAST('20150930 00:00:00' AS DATETIME)
WHILE (@VarDate2 <= '20151210') BEGIN
SET @VarDate2 = DATEADD(DAY, 1, @VarDate2)
SET @VarDate1 = @VarDate2
PRINT @VarDate2 --Change your logic here
END
GO