Simple FOR XML Explicit query to use on Northwind as a syntax reminder.... select 1 as tag, null as Parent, null as [TrackSales!1!hide], null as [Region!2!RegionName], null as [Territory!3!TerritoryName] union select 2 as TAG, 1 as Parent, null as [TrackSales!1!hide], rtrim(a.RegionDescription) as [Region!2!RegionName], null as [Territory!3!TerritoryName] from northwind.dbo.region a inner join northwind.dbo.territories b on a.regionid = b.regionid union select 3 as TAG, 2 as Parent, null as [TrackSales!1!hide], rtrim(a.RegionDescription) as [Region!2!RegionName], rtrim(b.TerritoryDescription) as [Territory!3!TerritoryName] from northwind.dbo.region a inner join northwind.dbo.territories b on a.regionid = b.regionid order by [Region!2!RegionName],[Territory!3!TerritoryName] for xml explicit