SELECT x.nsql_level , x.name , x.start , x.finish , x.uid , x.prwbssequence , CASE WHEN x.nsql_level < 2 THEN x.uid ELSE NULL END hg_has_children FROM ( select 1 nsql_level , i.name name , i.schedule_start start , i.schedule_finish finish , i.id UID , 0 prwbssequence from inv_investments i where i.ID = 5184386 --where @where:param:user_def:string:hg_row_id@ is null --and (@where:param:user_def:integer:param_project_id@ = i.id) group by name , i.schedule_start , i.schedule_finish , i.id union /* Level 2 - Program Key Milestones */ select 2 nsql_level , t.prname name , t.prstart start , t.prfinish finish , t.prid UID , t.prwbssequence from prtask t where t.prprojectid = 5184386 ) x order by x.nsql_level , x.prwbssequence