TSQL 返回 NO 或 YES 而不是 TRUE 或 FALSE
如果某些列返回 FALSE,我如何显示不同的值,
How can I show a different value if some columns return FALSE,
例如
COLUMN "BASIC" 返回 FALSE,但我需要为用户显示 YES 或 NO.案例 FALSE,返回 NO.
COLUMN "BASIC" returns FALSE, but I need show for the user YES or NO. Case FALSE, return NO.
推荐答案
如果是 varchar 或 bit,处理 NULLs
If varchar or bit, handling NULLs
case
when BASIC = 'FALSE' then 'NO'
when BASIC <> 'FALSE' then 'YES'
else 'UNDEFINED'
end
或者如果只是一点
case
when BASIC = 1 then 'YES'
when BASIC = 0 then 'NO'
else 'UNDEFINED'
end
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";
相关文章