如果列有 0 值,我需要选择像 'xyz' 和其他选择列值
例如,
id col1 col2
1 0 abc
2 2 xyz
我需要选择此表中的所有列,但col1
如果有 0 则需要显示“xyz”。
如果列有 0 值,我需要选择像 'xyz' 和其他选择列值
例如,
id col1 col2
1 0 abc
2 2 xyz
我需要选择此表中的所有列,但col1
如果有 0 则需要显示“xyz”。
select id,
case when col1 = '0' then 'xyz' else convert(varchar, col1) end as col1,
col2
from table
您必须使用 CASE :)
Select id, Case when col1 = 0 then 'xyz' else cast(col1 as varchar(10)) end as col1, col2 from table
select id,
case
when col1 = 0 then 'xyz'
else cast(col1 as varchar(50))
end as result_column,
col2
from table