create view expense_budget_view as
select 1 expense_budget_type,
c.customer_key,
c.customer_code project_org_code,
p.project_key,
p.project_code,
t.task_key,
t.task_name,
et.expense_type,
et.expense_type_name,
et.markup master_markup,
pet.markup project_markup,
etb.expense_type_key,
etb.description,
etb.begin_date,
etb.end_date,
etb.amount,
etb.use_wbs_dates
from expense_task_budget etb
join project p on p.project_key = etb.project_key
join customer c on c.customer_key = p.customer_key
join expense_type et on et.expense_type_key = etb.expense_type_key
left outer join task t on t.task_key = etb.task_key
left outer join project_expense_type pet on pet.expense_type_key = etb.expense_type_key and pet.project_key = etb.project_key
union all
select 2 expense_budget_type,
c.customer_key,
c.customer_code project_org_code,
p.project_key,
p.project_code,
null task_key,
null task_name,
et.expense_type,
et.expense_type_name,
epb.expense_type_key,
et.markup master_markup,
pet.markup project_markup,
epb.description,
epb.begin_date,
epb.end_date,
epb.amount,
epb.use_wbs_dates
from expense_project_budget epb
join project p on p.project_key = epb.project_key
join customer c on c.customer_key = p.customer_key
join expense_type et on et.expense_type_key = epb.expense_type_key
left outer join project_expense_type pet on pet.expense_type_key = epb.expense_type_key and pet.project_key = epb.project_key
|