Select case with expression and setting the Else result

Asked

Viewed 201 times

0

Personal someone can help me with a select case problem, I need to make a select of an expression and if that expression gives a negative result, it shows me the value, if positive the value has to be changed to zero, but I’m not getting it wrong when changing the value to zero, and my alias to name 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 

1 answer

0


from what I understand you are not sending the response options for the same attribute but for different attributes, tends with this code, or if possible make available some result lines for example.

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 ))
else
    0
end as saldo
from TB_REGISTRO_PONTO 
  • Opa got it right, that’s what I was wrong I got it right here, thank you very much!!

Browser other questions tagged

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