title: carriage return in sql server 2012
body: <p>Hey I am using the following query to display the problem list separated by commas.</p>
  
  <pre><code>SELECT tt.VrNo, STUFF((select ','+ Er1.ErrorDesc 
  from ( select * from CallRegErrors )as Main 
  left join ErrorMaster ER1 on Main.ErrorCode=ER1.ErrorCode
  WHERE (main.VrNo = tt.VrNo)
  FOR XML PATH('')) ,1,1,'') AS Problemlist
  </code></pre>
  
  <p>query is giving the output like a,b,c,d etc</p>
  
  <p>But my actual requirement is I want to display each error description in a new line like,<br/>
  a<br/>
  b<br/>
  c<br/>
  d<br/>
  etc</p>
  
  <p>I tried the following query for it:</p>
  
  <pre><code>SELECT tt.VrNo, STUFF((select char(13)+char(10)+ Er1.ErrorDesc
  from ( select * from CallRegErrors )as Main 
  left join ErrorMaster ER1 on Main.ErrorCode=ER1.ErrorCode
  WHERE (main.VrNo = tt.VrNo)
  FOR XML PATH('')) ,1,1,'') AS Problemlist
  </code></pre>
  
  <p>and also i have used </p>
  
  <p>SELECT tt.VrNo,Replace(STUFF((select ','+ Er1.ErrorDesc as [text()] from ( select * from CallRegErrors )as Main left join ErrorMaster ER1 on Main.ErrorCode=ER1.ErrorCode
              WHERE (main.VrNo = tt.VrNo)
              FOR XML PATH('')),1,1,''),',',char(13)+char(10)) AS Problemlist
              from (select main.VrNo, Er1.ErrorDesc from ( select * from CallRegErrors )as Main left join ErrorMaster ER1 on Main.ErrorCode=ER1.ErrorCode )as tt
              group by tt.VrNo 
  but now get the problem list seperated by spaces instead of commas after using the above query</p>
  
  <p>but its does not give the output that i want.</p>
  
  <p>please help..</p>
  
  <p>Thanks in advance</p>