SELECT CONSUMERID User_Group, RULENAME RightName, STRUCTURENAME StructureName, ELEMENTNAME ElementName, ELEMENTVALUE1 ElementValue1, ELEMENTVALUE2 ElementValue2, OPERAND Operand, rd.RULEGROUPING StructureGroup FROM dbo.ERS_RULEMASTER rm INNER JOIN dbo.ERS_RULEMAPPINGS rmp ON rm.RULEID=rmp.RULEID INNER JOIN dbo.ERS_STRUCTURE s ON rm.STRUCTUREID = s.STRUCTUREID INNER JOIN dbo.ERS_ELEMENTREFERENCES er ON s.STRUCTUREID=er.REFERENCEID INNER JOIN dbo.ERS_ELEMENTS e ON er.ELEMENTID=e.ELEMENTID LEFT OUTER JOIN dbo.ERS_RULEDETAIL rd ON rm.RULEID=rd.RULEID LEFT OUTER JOIN ERS_RULEVALUES rv ON rm.RULEID=rv.RULEID AND rd.RULEGROUPING=rv.RULEGROUPING AND rd.STRUCTUREID=rm.STRUCTUREID AND rd.ELEMENTID=rv.ELEMENTID