我希望在满足条件时显示在when语句时构建的多个字符串的串联。如下:
select
case
when T1.Field is not null then 'T1,'
when T2.Field is not null then /*last results*/ + 'T2,'
when T3.Field is not null then /*last results*/ + 'T3,'
end
from T1
left outer join T2 on ...
left outer join T3 on ...
答案 0 :(得分:4)
答案 1 :(得分:3)
终于找到了......我之前没有意识到这是可能的:
select
case when T1.Field is not null then 'T1,' else '' end
+ case when T2.Field is not null then 'T2,' else '' end
+ case when T3.Field is not null then 'T3,' else '' end as result
from T1
left outer join T2 on ...
left outer join T3 on ...