I'm trying to run the query below, but the following error occurs.
"Converting a varchar data type to a datetime data type resulted in a value out of 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