Question :
I have a sql query:
select
HORA_FECHAMENTO, --campo char no recebendo a hora no formato 18:00
CONVERT(VARCHAR(11),GETDATE(),114) as HORA_ATUAL
from TB_ESTRACAO where IDEXTRACAO = 4
I want to compare the server time, it must always be greater than the hour HOUR_DATE
Answer :
Although you have not specified the server version, there is a solution for version 2008 or later.
Declare @HORA_FECHAMENTO char (5)
Declare @HORA_ATUAL datetime
Set @HORA_FECHAMENTO='04:59'
Set @HORA_ATUAL = CAST(CONVERT(VARCHAR(11),GETDATE(),8) as time)
select
CAST(@HORA_FECHAMENTO AS time) as HORA_FECHAMENTO, --campo char no recebendo a hora no formato 18:00
CAST(CONVERT(VARCHAR(11),GETDATE(),8) as time) as HORA_ATUAL
IF @HORA_ATUAL > @HORA_FECHAMENTO
BEGIN
print 'Hora servidor maior'
END
HOUR_CONTACT | HORA_ATUAL
——————————– | —————-
04: 59: 00.0000000 | 04: 59: 11.0000000
(1 row (s) affected)
Larger server time