0
Guys, I’m trying to run the query below, however, the following error occurs.
"Conversion of a data type varchar into a data type datetime resulted in a value outside the range.".
select
MesID,Mes,Ano,
convert(time,dateadd(second,SUM ( DATEPART(hh,(convert(datetime,horas_uteis,1))) * 3600 +
DATEPART(mi, (convert(datetime,horas_uteis,1))) * 60 + DATEPART(ss,(convert(datetime,horas_uteis,1)))),0),108)
as horas
from (
select
dbo.FN_CALC_HORAS_UTEIS(s.SolDataFechamento,min(l.LogData)) as horas_uteis,
datepart(month,s.SolDataFechamento) MesID,
datename(month,s.SolDataFechamento) Mes,
datepart(year,s.SolDataFechamento) Ano
from Solicitacao S
left join usuario U on (U.UsuID = S.UsuIDResponsavel)
left join Status ST on S.SolStatus = ST.CodStatus
left join Log L on L.LogSolID = s.SolID
where
S.proid in (2)
and S.UsuIDResponsavel in (select UsuID from usuario where UsuIDGrupo = 1151 and EmpLiberada = 1 and UsuTipo = 'A'
and UsuID not in(84869,90093,95613,2359,596))
and s.SolStatus = 9
and l.LOGDESCRICAO like '%1057%' and convert(date,s.SolDataFechamento,103) between '01-01-2018' and '31-01-2018'
group by s.SolDataFechamento
having dbo.FN_CALC_HORAS_UTEIS(s.SolDataFechamento,min(l.LogData)) < '100:00'
) as X
group by MesID, Mes, Ano
what kind of return
FN_CALC_HORAS_UTEIS
? apparently trying to convert100:00
for datetime, which will not be possible. Until because in a timestamp, 100 hours would be something around 4 days and 3 hours– Rovann Linhalis
@Rovannlinhalis, the 100 in this case does not interfere, because apart from it, the same error occurs. The return of FN_CALC_HORAS_UTEIS are the working times between two dates.
– Renan Bessa
Which database are you using? The 100, it was just a suggestion, ok. Function return type can be timestamp, Numeric, etc...
– Rovann Linhalis
understood. I am using sql server 2012
– Renan Bessa
give an example of the data that is returned in the function, and that are placed in the column
horas_uteis
– Rovann Linhalis