title: How to convert newlines (replace \r\n with \n) across all varchar and nvarchar fields in a database
body: <p>I am recovering from a bug in a system I built where I did not take into account that IE generates Windows-style newlines (\r\n) and other browsers generate Unix-style newlines (\n) when posting HTML forms with text areas. Now I need to convert all Windows-style newlines (\r\n) to Unix-style newlines (\n) throughout the varchar and nvarchar fields in my SQL-Server database.</p>
  
  <p>Is there a way to iterate through all tables/rows in T-SQL and replace instances of '\r\n' with '\n' for varchar and nvarchar fields?</p>
  
  <p>EDIT: I think the replace part would be something like</p>
  
  <pre><code>REPLACE(@fieldContents, CHAR(13)+CHAR(10), CHAR(10))
  </code></pre>
  
  <p>The hard part is doing this across all varchar and nvarchar fields.</p>