In the following how can I pull the staff name (first and last) from the staffmaster file instead of staffmasterid_c from the enrollments table (ec,ew & ed)?
select c.uniqueid_c,
c.clientcode_c,
a.type_c as a_type,
a.address1_vc,
a.address2_vc,
a.address3_vc,
a.city_vc,
a.state_c,
a.zip_c,
a.county_vc,
p.type_c as p_type,
p.commentry_vc,
ec.staffmasterid_c as clinician,
ew.staffmasterid_c as caseworker,
ed.staffmasterid_c as doctor
from ar.client as c
left join echo.er_address as a on (c.uniqueid_c = a.linkid_c and a.type_c ='client' and a.enddate_d is null)
left join echo.er_communication as p on (c.uniqueid_c = p.linkid_c and p.type_c ='client' and p.enddate_d is null)
left join cd.enrollments as ec on (c.uniqueid_c = ec.clientid_c and ec.program_c = '500' and ec.enddate_d is null and (ec.ru_c is null or ec.ru_c = 'wrkr'))
left join cd.enrollments as ew on (c.uniqueid_c = ew.clientid_c and ew.program_c = '100' and ew.enddate_d is null and (ew.ru_c is null or ew.ru_c = 'wrkr'))
left join cd.enrollments as ed on (c.uniqueid_c = ed.clientid_c and ed.program_c = '900' and ed.enddate_d is null and (ed.ru_c is null or ed.ru_c = 'wrkr'))
where c.admstat_c = 'open'
Thanks - Paul
select c.uniqueid_c,
c.clientcode_c,
a.type_c as a_type,
a.address1_vc,
a.address2_vc,
a.address3_vc,
a.city_vc,
a.state_c,
a.zip_c,
a.county_vc,
p.type_c as p_type,
p.commentry_vc,
ec.staffmasterid_c as clinician,
ew.staffmasterid_c as caseworker,
ed.staffmasterid_c as doctor
from ar.client as c
left join echo.er_address as a on (c.uniqueid_c = a.linkid_c and a.type_c ='client' and a.enddate_d is null)
left join echo.er_communication as p on (c.uniqueid_c = p.linkid_c and p.type_c ='client' and p.enddate_d is null)
left join cd.enrollments as ec on (c.uniqueid_c = ec.clientid_c and ec.program_c = '500' and ec.enddate_d is null and (ec.ru_c is null or ec.ru_c = 'wrkr'))
left join cd.enrollments as ew on (c.uniqueid_c = ew.clientid_c and ew.program_c = '100' and ew.enddate_d is null and (ew.ru_c is null or ew.ru_c = 'wrkr'))
left join cd.enrollments as ed on (c.uniqueid_c = ed.clientid_c and ed.program_c = '900' and ed.enddate_d is null and (ed.ru_c is null or ed.ru_c = 'wrkr'))
where c.admstat_c = 'open'
Thanks - Paul