select 'dbr.count', 'Name';
select 'dbr.hdr', 'Designation';
select t.designation 'Designation', c.competency_c 'Master Category',
concat(t.first_name, ' ',t.last_name) 'Name',
c.region_c 'Region',
case c.business_unit_c
when 'BI' then 'BI Team'
when 'SUP' then 'Support Staff'
when 'MNG' then 'Management'
else replace(business_unit_c, '_', ' ')
end 'Business Area',
a.name 'Based at',
concat(u.first_name, ' ', u.last_name) 'Reports to',
c.type_c 'Contractual/Permanent'
from teammember_cstm c
left outer join teammember t on (t.id = c.id_c and t.deleted = 0)
left outer join users u on u.id = t.user_id1_c
left outer join accounts a on c.account_id_c = a.Id
where a.deleted = 0
and c.status_c ='Active' and (type_c in (select tType from teammember_types)) and
Company_c = inCompany
end
and c.status_c ='Active'
and t.deleted=0
and (c.region_c = inRegion or inRegion = 'All')
order by 1; -- 1 being designation