我需要编写一个返回一列的查询,这取决于2列中是否存在值:
列是:C1和C2,它们在同一个表T中。如果C1存在则返回C1,如果C1不存在则返回C2。
答案 0 :(得分:0)
select case when isnull(C1,'')<>'' then C1
when isnull(C2,'')<>'' then C2
end as Column_name
from table T
答案 1 :(得分:0)
select case when isnull(C1,'')<>'' then C1
else C2
end as Column_name
from table T
Case statement在这里使用。