title: Unable to use order by clause with for xml path properly(Sql server)
body: <p>I have the below situation (say tblRecord)</p>
  
  <pre><code>ID RowNum  Data
  1 1  and seventy nine
  1 2  five hundred
  1 3  two thousand
  </code></pre>
  
  <p>I need the output to be</p>
  
  <pre><code>ID   Data
   1   two thousand five hundred and seventy nine
  </code></pre>
  
  <p>I have the below query</p>
  
  <pre><code>select ID , Data = 
    ( Select ' ' + cast(Data as varchar(max)) from tblRecord t2
                    where t2.RowNum= t1.RowNum
                    and t2.ID =t1.ID
                    order by t1.RowNum
                    for xml path(''))
  from tblRecord t1
  group by t1.ID
  </code></pre>
  
  <p>But the output is </p>
  
  <pre><code>ID  Data
  1 five hundred two thousand and seventy nine
  </code></pre>
  
  <p>Help needed for this.</p>
  
  <p>Thanks</p>