Why below code give开发者_如何转开发s me 0 or zero instead of blank value or blank row in column ValueA.
How can I change it to blank value?
select ValueA = case when ValueB = 'No' then ValueA
when ValueB = 'Yes' then ''
else ''
end
From Table
or
if I use ValueB = 'Yes' then CAST(NULL AS varchar(25))
gives me Null
and I want blank where it is Null, but when I try to convert to blank
I get zero. Why?
How can I get blank?
Sounds like ValueA is equal to 0.
Because valueA is a number, and it can't contain a "blank row". It's either going to be 0 or NULL. If you want blanks, you need to use varchar or an equivalent character field.
ValueA must be a numeric data type. Also, your WHEN 'Yes'
and ELSE
are redundant. Try:
SELECT ValueA = CASE ValueB
WHEN 'No' THEN CONVERT(VARCHAR(25), ValueA)
ELSE '' END
FROM dbo.[Table];
select
case when ValueB = 'No' then Cast(ValueA as VarChar(10))
when ValueB = 'Yes' then ''
else ''
end as ValueA
From Table
精彩评论