Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TSQL to return NO or YES instead TRUE or FALSE

Tags:

How can I show a different value if some columns return FALSE,

for example,

COLUMN "BASIC" returns FALSE, but I need show for the user YES or NO. Case FALSE, return NO.

like image 970
Lucas_Santos Avatar asked Nov 08 '11 14:11

Lucas_Santos


People also ask

How display True or False in SQL?

There are no built-in values true and false . One alternative is to use strings 'true' and 'false' , but these are strings just like any other string. Often the bit type is used instead of Boolean as it can only have values 1 and 0 . Typically 1 is used for "true" and 0 for "false".

How can check true or false in SQL Server?

SQL Server IIF() Function The IIF() function returns a value if a condition is TRUE, or another value if a condition is FALSE.

Is it better to use <> or != In SQL?

If != and <> both are the same, which one should be used in SQL queries? Here is the answer – You can use either != or <> both in your queries as both technically same but I prefer to use <> as that is SQL-92 standard.


1 Answers

If varchar or bit, handling NULLs

case     when BASIC = 'FALSE' then 'NO'     when BASIC <> 'FALSE' then 'YES'     else 'UNDEFINED' end 

or if just bit

case     when BASIC = 1 then 'YES'     when BASIC = 0 then 'NO'     else 'UNDEFINED' end 

Edit:

SELECT      TipoImovel_Id AS TII_SEQ,     Descricao AS TII_DSC,      Sigla AS TII_DSC_SIGLA,     -- choose which one you want from the answers here     case         when BASIC = 1 then 'YES'         when BASIC = 0 then 'NO'         else 'UNDEFINED'     end AS SomeColumnName FROM San_TipoImovel"; 
like image 134
gbn Avatar answered Sep 29 '22 15:09

gbn