select
dbo.MatterPlayer.MatterNumber_ID,
dbo.Entity.Name as Participating_Business_Unit,
null as Primary_Business_Unit
From dbo.Entity
INNER JOIN dbo.MatterPlayer ON ( dbo.Entity.Entity_EID = dbo.MatterPlayer.Entity_EID AND dbo.MatterPlayer.Role_CD = 'Participating Business Unit' )
union
select
dbo.MatterPlayer.MatterNumber_ID,
null as Participating_Business_Unit,
dbo.Entity.Name as Primary_Business_Unit
From dbo.Entity
INNER JOIN dbo.MatterPlayer ON ( dbo.Entity.Entity_EID = dbo.MatterPlayer.Entity_EID AND dbo.MatterPlayer.Role_CD = 'Primary Business Unit' )
Quick question…do you have a need to do this at the universe level ?
Have you considered doing this at the report level, using 2 data proiders and merging the 2 on Matter ID ?
BTW…the union is doing what it is supposed to do, eleminating duplicates and in your case there are not really any duplicate rows.
What you need is a join and not union…
If you want to stick to derived tables try creating 2 derived tables (one for participating Bu and the other for primary BU) and joining the 2.
You need to pivot the data, the general idea would be as follows
select MatterNumber_ID,
max(case when Role_cd='Participating Business Unit' then Entity.Name else null end),
max(case when Role_cd = 'Primary Business Unit' then Entity.Name else null end)
from <your tables, joins, etc.>
group by MatterNumber_ID