Doubt Case SqlServer

0

I'm using the following case:

 CASE WHEN RESPOSTA.CD_RESPOSTA = 1 THEN 'ATENDE'
      WHEN RESPOSTA.CD_RESPOSTA = 2 THEN 'NÃO ATENDE'
      ELSE 'NÃO APLICÁVEL' END AS DS_RESPOSTA

I have the value of ANSWER.CD_RESPOSTA: 2. The field is an Int, not null.

But it's always coming back to me 'NOT APPLICABLE'. What am I doing wrong?

    
asked by anonymous 29.05.2018 / 15:54

1 answer

0

Do a conversion treatment for the field as shown in the example below. In this way it is possible to guarantee what data exists in the data origin. Depending on the results, you can treat the data source so that conversion is not necessary.

 CASE 
  WHEN CONVERT(INT, ISNULL(RESPOSTA.CD_RESPOSTA, 0)) = 1 THEN 'ATENDE'
  WHEN CONVERT(INT, ISNULL(RESPOSTA.CD_RESPOSTA, 0)) = 2 THEN 'NÃO ATENDE'
  ELSE 'NÃO APLICÁVEL' END AS DS_RESPOSTA
    
29.05.2018 / 18:35