I have a problem with a select case, I need to do a select of an expression and if this expression gives a negative result, it shows me the value, if it is positive the value has to be changed to zero, but I can not get ta giving error when changing the value to zero, and my alias to name the table tmb does not work, follow the query below:
select case
when DATEDIFF(MINUTE,HR_ENTRADA,HR_SAIDA) - DATEDIFF(MINUTE,HR_SAIDA_ALMOCO,HR_ENTRADA_ALMOCO ) < 0
then (select DATEDIFF(MINUTE,HR_ENTRADA,HR_SAIDA) - DATEDIFF(MINUTE,HR_SAIDA_ALMOCO,HR_ENTRADA_ALMOCO ) as saldo)
else
set saldo = 0
end
from TB_REGISTRO_PONTO