USE AdventureWorks2012;
GO
SELECT 1 as Tag,
NULL as Parent,
E.BusinessEntityID as [Employee!1!EmpID],
BEA.AddressID as [Employee!1!AddressID],
NULL as [Address!2!AddressID],
NULL as [Address!2!AddressLine1!ELEMENT],
NULL as [Address!2!AddressLine2!ELEMENTXSINIL],
NULL as [Address!2!City!ELEMENTXSINIL]
FROM HumanResources.Employee AS E
INNER JOIN Person.BusinessEntityAddress AS BEA
ON E.BusinessEntityID = BEA.BusinessEntityID
UNION ALL
SELECT 2 as Tag,
1 as Parent,
E.BusinessEntityID,
BEA.AddressID,
A.AddressID,
AddressLine1,
AddressLine2,
City
FROM HumanResources.Employee AS E
INNER JOIN Person.BusinessEntityAddress AS BEA
ON E.BusinessEntityID = BEA.BusinessEntityID
INNER JOIN Person.Address AS A
ON BEA.AddressID = A.AddressID
ORDER BY [Employee!1!EmpID],[Address!2!AddressID]
FOR XML EXPLICIT;