如果某些列返回FALSE,
,如何显示不同的值例如,
COLUMN“BASIC”返回FALSE,但我需要为用户显示YES或NO。情况FALSE,返回NO。
答案 0 :(得分:43)
如果是varchar或bit,则处理NULL
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";
答案 1 :(得分:6)
case when column = 'FALSE' then 'NO' else 'YES' end
答案 2 :(得分:0)
使用CASE
声明:
case BASIC when 'True' then 'Yes' ELSE 'No' end
答案 3 :(得分:0)
像这样:
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
答案 4 :(得分:0)
你可以创建一个用户定义的函数,以便将来你可以说:
select dbo.YesNo(Active) from APAccount
这是函数
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