in the SQL query below, I can run normally on the SQL Server Query. However, when using within a system developed by me, it gives the following message: "The Conversion of a VARCHAR DATA TYPE TO A DATEETIME DATA TYPE RESULTED IN AN OUT-OF-RANGE VALUE."
I have tried to use Convert and Cast, but even then it gives this error. How to solve?
select x.CODPESSOA
from vatestado x
where x.codcoligada = 1
group by x.codpessoa
having sum(datediff(day, DTINICIO, DTFINAL)) >= 2