title: How to merge rows into single column using FOR XML PATH in sql?
body: <p>I want to <strong>merge rows into single column</strong> using <code>FOR XML PATH</code> in <code>SQL</code>.</p>
  
  <p>Here is my Query:</p>
  
  <pre><code>select d.Device from tbl_Sales_OrderItems tsoi left join tbl_devices d 
  on d.DeviceID=tsoi.DeviceID
  where salesorderid=102 
  and tsoi.Quantity&gt;0
  and tsoi.TypeID=1
  
  union all
  
  select d.Partnumber Device from tbl_Sales_OrderItems tsoi left join tbl_VendorParts d 
  on d.VendorPartID=tsoi.RefID
  where salesorderid=102 
  and tsoi.Quantity&gt;0
  and tsoi.TypeID=2
  </code></pre>
  
  <p>Here i am getting two rows i.e Two Device name in from <code>tbl_Sales_Order</code>. </p>
  
  <p><em>Now these rows i want to get in single row using <code>FOR XML PATH</code> into a single column.</em> </p>
  
  <p>Further after applying <code>FOR XML PATH</code> i want to use it in <code>select query</code> i want to use the row value which would be as follows.</p>
  
  <pre><code>Select salesorderid,@resultinRow from tbl_Sales_Orders
  </code></pre>
  
  <p><strong>Output Required:</strong></p>
  
  <pre><code>SalesOrderID  Devices
    102          Device1,Device2
    103          Device3,Device2
  </code></pre>