Concatenate the result of multiple case when statement

sql-server-2005, t-sql

Solution

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 ...

Problem

I would like to display a concatenation of multiple string built upon when statement when the condition is met. As follow : ``` 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 ... ```

Original source