2

我想在满足条件时显示基于 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 ...
4

2 回答 2

7

Finally found out ... I didn't realize this was possible before :

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 ...
于 2013-08-13T07:24:55.837 回答
4

为什么不尝试使用ISNULL

就像是

ISNULL(T1.Field,'') + ISNULL(T2.Field,'') + ... + ISNULL(TN.Field,'')
于 2013-08-13T06:59:16.623 回答