Error while running script

Asked

Viewed 68 times

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 convert 100:00 for datetime, which will not be possible. Until because in a timestamp, 100 hours would be something around 4 days and 3 hours

  • @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.

  • Which database are you using? The 100, it was just a suggestion, ok. Function return type can be timestamp, Numeric, etc...

  • understood. I am using sql server 2012

  • give an example of the data that is returned in the function, and that are placed in the column horas_uteis

1 answer

0

Apparently you tried to make a conversion of varchar for date which resulted in an invalid date, as per example 30-02-2018.

Check predicates and conversions performed in your header SQL involving dates in the operation and if any of them are invalid.

  • notice that I have set a date referring to the month of January and there is no exit from 30-02-2018;

  • 1

    Note that I did not say that you reported 30-02-2018, I used only such date as an example of an invalid period.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.