title: Generate Empty xml root node in SQL even if there are no records
body: <p>I have a problem with generating empty\null xml root node from sql. This is an exmaple of the structure that I'm working on:</p>
  
  <pre><code>&lt;Departments&gt;
      &lt;Department&gt;
          &lt;Employees&gt;
           &lt;Employee&gt;
              &lt;Name&gt;&lt;/Name&gt;
              &lt;ID&gt;&lt;/ID&gt;
           &lt;/Employee&gt;
          &lt;/Employees&gt;
      &lt;/Department&gt;
      &lt;/Departments&gt;
  </code></pre>
  
  <p>Below is the sql that I use to generate the structure :</p>
  
  <pre><code>declare @Employee table (Name varchar(50), ID int, DID int)
  declare @Department table (Name varchar(50), DID int)
  declare @xmldata xml
  
  insert into @Employee values ('AAA', 1, 3)
  insert into @Employee values ('BBB', 2, 3)
  --insert into @Department values ('CCC', 3)
  
  SET @xmldata = 
  (
  
  select GETDATE() as 'ReportDate', (
  
  select D.Name,
  (
  select (
         select E.Name,
                E.ID
         from @Employee E
      where E.DID = D.DID
         for xml path ('Employee'), elements xsinil, type    
         )
  for xml path('Employees'), type
  )
  from @Department D
  for xml path('Department'), type
  )
  
  for xml path ('Departments'), type
  )
  select @xmldata
  </code></pre>
  
  <p>If there are records, the xml structure is coming properly but my problem is if there are no department record, there is no  node at all. How do I show at least the  empty node in the xml? </p>
  
  <p>If no department record, xml will be :</p>
  
  <pre><code>&lt;Departments&gt;
    &lt;ReportDate&gt;2016-08-11T16:31:22.960&lt;/ReportDate&gt;
  &lt;/Departments&gt;
  </code></pre>
  
  <p>What I like to have is :</p>
  
  <pre><code>&lt;Departments&gt;
    &lt;ReportDate&gt;2016-08-11T16:31:22.960&lt;/ReportDate&gt;
    &lt;Department /&gt;
  &lt;/Departments&gt;
  </code></pre>