How to make a SE function in SQL

Asked

Viewed 2,686 times

-1

Good morning.

How do I make a SE function in SQL server? For example, I have data in a column and when it is = '1';'masculino';'feminino'.

You can help me please?

  • The claudia WHERE serves or needs the same if?

  • You know, how I would do that in the code?

  • select case WHEN a.genero = '1' then 'Male' Else 'Female' end as genero from table

  • One option is the IIF() function, if the SQL Server version is 2012 or later.

1 answer

1


In this case, the ideal is for you to use the CASE, since the return depends on the data validation of a specific field:

SELECT CASE WHEN campo_genero = '1' THEN 'Masculino' ELSE 'Feminino' END
FROM nome_tabela
  • 1

    Perfect rLinhares. Thanks, abs.

Browser other questions tagged

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