TSQL para devolver NO o SÍ en lugar de VERDADERO o FALSO

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

por ejemplo,

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

preguntado el 08 de noviembre de 11 a las 14:11

There are no Boolean true/false columns in SQL Server. Tell us what is the data type of column BASIC. -

6 Respuestas

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";

respondido 08 nov., 11:18

but how can I put this in my query ? "SELECT TipoImovel_Id AS TII_SEQ, Descricao AS TII_DSC, Sigla AS TII_DSC_SIGLA, basic FROM San_TipoImovel"; The basic I need return YES or NO case TRUE or FALSE - Lucas_Santos

since SQL 2012 you can use IIF function

IIF(BASIC = 'TRUE', 'YES', 'NO')

respondido 04 mar '17, 00:03

case when column = 'FALSE' then 'NO' else 'YES' end

respondido 08 nov., 11:18

but how can I put this in my query ? "SELECT TipoImovel_Id AS TII_SEQ, Descricao AS TII_DSC, Sigla AS TII_DSC_SIGLA, basic FROM San_TipoImovel"; The basic I need return YES or NO case TRUE or FALSE - Lucas_Santos

Utilizan CASE declaración:

case BASIC when 'True' then 'Yes' ELSE 'No' end

respondido 08 nov., 11:18

You need to wrap your literals in single quotes - Mark Kram

Me gusta:

SELECT TipoImovel_Id AS TII_SEQ, Descricao AS TII_DSC, Sigla AS TII_DSC_SIGLA, case when basic = 'FALSE' then 'NO' else 'YES' end 
FROM San_TipoImovel

respondido 08 nov., 11:23

You could create a user defined function so in the future you can just say something like:

select dbo.YesNo(Active) from APAccount

aquí está la función

CREATE FUNCTION [dbo].YesNo(@Value Bit)
    RETURNS varchar(3)
    BEGIN
      DECLARE @R as varchar(3)

      SET @R =
        (
        Select 
            case 
                when @Value = 1 then 'Yes'
                else 'No'
            end
        )
       RETURN @R
    END

respondido 15 mar '15, 20:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.