Ho usato la data e la validazione di tempo per la pianificazione di un rapporto ... devo programmare che i rapporti per data futura e l'ora e non la data precedente e time..I hanno usato questaErrore di confronto con data/ora in 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
Per data di parte si sta controllando in modo corretto, ma per il tempo che sta gettando errore
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)'. Qui. stai cercando di ottenere la differenza in secondi mentre lo assegni a una variabile chiamata '@ Hr'. Non hai bisogno di 'HH' invece di' S'? Inoltre, perché usare un varchar per '@ Hr'? – shahkalpesh