1

如果列有 0 值,我需要选择像 'xyz' 和其他选择列值

例如,

 id    col1   col2
 1       0     abc
 2       2     xyz

我需要选择此表中的所有列,但col1如果有 0 则需要显示“xyz”。

4

3 回答 3

3
select id,
       case when col1 = '0' then 'xyz' else convert(varchar, col1) end as col1,
       col2
from table

您必须使用 CASE :)

于 2012-05-10T08:44:53.857 回答
1
Select id, Case when col1 = 0 then 'xyz' else cast(col1  as varchar(10)) end as col1, col2 from table
于 2012-05-10T08:41:13.463 回答
1
select id,
       case 
         when col1 = 0 then 'xyz' 
         else cast(col1 as varchar(50))
       end as result_column,
       col2
from table
于 2012-05-10T08:47:21.187 回答