我已经使用日期和时间验证调度的报告...我有安排,对于未来的日期和时间,而不是以前的日期和time..I报告都用这个SQL日期时间比较错误?
declare @Dt varchar(50)
declare @Hr varchar(50)
declare @trandate_time_tmp as TIME(0)
select @trandate_time_tmp = getdate()
set @Dt = DATEDIFF (D,@schedule_date ,@trandate_tmp)
set @Hr = DATEDIFF (S,@schedule_date ,@trandate_time_tmp)
if (@Dt > 0)
begin
raiserror('Schedule Date should not be earlier than system date',16,1)
return
end
if (@Hr > 0)
begin
raiserror('Schedule Time should not be earlier than system time',16,1)
return
end
对于日期部分它是正确的,但检查时间它抛出的错误作为
The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.
`set @Hr = DATEDIFF(S,@ schedule_date,@ trandate_time_tmp)`。这里。你试图在几秒钟内获得差异,而将其分配给一个名为`@ Hr`的变量。你不需要`HH`而不是`S`?另外,为什么使用`@ Hr`的varchar? – shahkalpesh 2011-02-10 07:06:24