Subject | Re: SQL question (generic - not FB specific) |
---|---|
Author | Ian A. Newby |
Post date | 2006-01-17T16:45:23Z |
Hi Kjell,
how about:
select t1.Chairman as name,'Chairman' || coalesce((select ',CEO' from
table t2 where t2.CEO = t1.chairman), '') || coalesce((select ',CFO'
from table t2 where t2.CFO = t1.chairman), '') || coalesce((select
',IT Manager' from table t2 where t2.ITManager = t1.chairman), '')
from table t1 where chairman is not null
union
select t1.CEO as name,'CEO' || coalesce((select ',CFO' from table t2
where t2.CFO = t1.CEO), '') || coalesce((select ',IT Manager' from
table t2 where t2.ITManager = t1.CEO), '') from table t1 where
chairman is null and CEO is not null
union
select t1.CFO as name,'CFO' || coalesce((select ',IT Manager' from
table t2 where t2.ITManager = t1.CFO), '') from table t1 where
chairman is null and CEO is null and CFO is not null
union
select t1.CFO as name,'IT Manager' from table t1 where chairman is
null and CEO is null and CFO is null and ITManager is not null
Just a thought.
Regards
Ian Newby
how about:
select t1.Chairman as name,'Chairman' || coalesce((select ',CEO' from
table t2 where t2.CEO = t1.chairman), '') || coalesce((select ',CFO'
from table t2 where t2.CFO = t1.chairman), '') || coalesce((select
',IT Manager' from table t2 where t2.ITManager = t1.chairman), '')
from table t1 where chairman is not null
union
select t1.CEO as name,'CEO' || coalesce((select ',CFO' from table t2
where t2.CFO = t1.CEO), '') || coalesce((select ',IT Manager' from
table t2 where t2.ITManager = t1.CEO), '') from table t1 where
chairman is null and CEO is not null
union
select t1.CFO as name,'CFO' || coalesce((select ',IT Manager' from
table t2 where t2.ITManager = t1.CFO), '') from table t1 where
chairman is null and CEO is null and CFO is not null
union
select t1.CFO as name,'IT Manager' from table t1 where chairman is
null and CEO is null and CFO is null and ITManager is not null
Just a thought.
Regards
Ian Newby